POJ 2502 Subway 最短路 Floyd
2016-08-18 17:16
375 查看
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
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 =a,Y =b,T++,N++; } X =EX,Y =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] <<endl; return 0; }
相关文章推荐
- 将动态库打包在Jar包并调用的方法
- 语言能够自己不断迭代精进学习
- 获取磁盘容量
- iOS 面试题搜集
- C#正则表达式的学习
- dpkg命令的用法
- Epoll模型详解
- 数据归一化和两种常用的归一化方法
- Linux用户身份切换
- 基于JDK动态代理和CGLIB动态代理的实现Spring注解管理事务(@Trasactional)到底有什么区别。
- 车牌识别项目——当前技术(1)
- HDU 1176 免费馅饼 dp
- js_BOM
- Call to undefined function curl_init()解决方法
- ViewPager的广告轮播功能
- 数据结构——13 队列链表描述
- MySql中delimiter的作用是什么?
- [技术随笔(二)] win10 回滚 win7 注意事项
- USB初始化
- jquery easyui使用(四)······添加,编辑,删除