POJ 2502 Subway 最短路 Floyd
来源:互联网 发布:1hhh域名升级访问 编辑:程序博客网 时间:2024/05/04 01:31
Subway
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8733 Accepted: 2821
Description
You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don’t want to be late for class, you want to know how long it will take you to get to school.
You walk at a speed of 10 km/h. The subway travels at 40 km/h. Assume that you are lucky, and whenever you arrive at a subway station, a train is there that you can board immediately. You may get on and off the subway any number of times, and you may switch between different subway lines if you wish. All subway lines go in both directions.
Input
Input consists of the x,y coordinates of your home and your school, followed by specifications of several subway lines. Each subway line consists of the non-negative integer x,y coordinates of each stop on the line, in order. You may assume the subway runs in a straight line between adjacent stops, and the coordinates represent an integral number of metres. Each line has at least two stops. The end of each subway line is followed by the dummy coordinate pair -1,-1. In total there are at most 200 subway stops in the city.
Output
Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.
Sample Input
0 0 10000 1000
0 200 5000 200 7000 200 -1 -1
2000 600 5000 600 10000 600 -1 -1
Sample Output
21
Source
Waterloo local 2001.09.22
//上午搞错了一个点 一条线路上1,2的速度是40 不代表从1直接到3的速度也是40...建图的时候要注意了//建完图后floyd搞一搞//测试的时候用Ctrl+Z结束输入#include<stdio.h>#include<string>#include<cstring>#include<queue>#include<algorithm>#include<functional>#include<vector>#include<iomanip>#include<math.h>#include<iostream>#include<sstream>#include<stack>#include<set>#include<bitset>using namespace std;const double INF=1000000000000;int N,a,b,S,T,EX,EY;int X[205],Y[205];double Dis[205][205];double GetDis(int i,int j,int speed){ return sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]))*60/1000/speed;}void Floyd(){ for (int k=0; k<=N; k++) for (int i=0; i<=N; i++) for (int j=0; j<=N; j++) if (Dis[i][j]>Dis[i][k]+Dis[k][j]) Dis[i][j]=Dis[i][k]+Dis[k][j];}int main(){ cin.sync_with_stdio(false); cout<<fixed<<setprecision(0); for (int i=0;i<205;i++) for (int j=0;j<205;j++) Dis[i][j]=INF; cin>>X[0]>>Y[0]>>EX>>EY; N=1,S=1,T=0; while (cin>>a>>b) { if (a==-1&&b==-1) { for (int i=S;i<T;i++) Dis[i][i+1]=Dis[i+1][i]=GetDis(i,i+1,40); S=T+1; T=S-1; continue; } X[N]=a,Y[N]=b,T++,N++; } X[N]=EX,Y[N]=EY; for (int i=0;i<205;i++) Dis[i][i]=0; for (int i=0;i<=N;i++) for (int j=i+1;j<=N;j++) Dis[i][j]=Dis[j][i]=min(Dis[i][j],GetDis(i,j,10)); Floyd(); cout<<Dis[0][N]<<endl; return 0;}
- POJ 2502 Subway 最短路 Floyd
- POJ 2502 Subway(最短路)
- poj 2502 subway (最短路)
- [POJ 2502]Subway[最短路]
- poj 2502最短路subway
- POJ 2502 Subway(Floyd单源最短路)
- 最短路练习12/poj/2502 Subway dijkstar,spfa,floyd都可以解决
- poj 2502 Subway(dijkstra 最短路)
- poj 2502 Subway (最短路 Dijksta)
- 【POJ 2502】Subway(最短路dij)
- POJ-2502 Subway(最短路 Dijkstra)
- POJ 2502 Subway 单源点最短路模板
- POJ 2502 Subway (Dijkstra 最短路+建图)
- POJ 3165 最短路 floyd
- POJ 2253 floyd 最短路
- poj 2253 floyd最短路!!!
- poj 1847 最短路 floyd
- POJ 1125 最短路 FLOYD
- 数据归一化和两种常用的归一化方法
- Epoll模型详解
- 数据结构——14 循环队列
- C#正则表达式的学习
- select、poll、epoll之间的区别总结[整理]
- POJ 2502 Subway 最短路 Floyd
- poll&&epoll实现分析(一)——poll实现
- Java生成对象的四种方法
- php 比较运算符'=='的使用技巧
- 数据结构实验之二叉树一:树的同构
- 杭电5480Conturbatio
- 使用Gradle发布aar项目到JCenter仓库
- 多功能下载器设计与使用过程
- input 标签如何multiple 上传多张图片 实时在页面显示图片