POJ2502 Subway(Floyd)
2015-08-09 08:58
447 查看
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
Sample Output
输入确实是坑。。我在本地都没有办法测试数据 硬是wa了数十次
floyd dijkstra spfa均可做
我觉得这题比较难的是建图。。 其实是因为自己不会建。。。
AC代码:
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
输入确实是坑。。我在本地都没有办法测试数据 硬是wa了数十次
floyd dijkstra spfa均可做
我觉得这题比较难的是建图。。 其实是因为自己不会建。。。
AC代码:
#include "iostream" #include "cstdio" #include "cstring" #include "algorithm" #include "cmath" using namespace std; const int MAXN = 305; struct node { /* data */ double x, y; }point[MAXN]; double map[MAXN][MAXN], subv, walkv; int n; double dist(node a, node b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main(int argc, char const *argv[]) { for(int i = 0; i < MAXN; ++i) for(int j = 0; j < MAXN; ++j) map[i][j] = -1; subv = 40 * 1000.0 / 60; walkv = 10 * 1000.0 / 60; for(int i = 0; i < 2; ++i) scanf("%lf%lf", &point[i].x, &point[i].y); n = 2; node last, now; last.x = last.y = -1; while(scanf("%lf%lf", &now.x, &now.y) != EOF) { if(!(now.x == -1 && now.y == -1)) { point[n++] = now; if(!(last.x == -1 && last.y == -1)) map[n - 1][n - 2] = map[n - 2][n - 1] = dist(point[n - 1], point[n - 2]) / subv; } last = now; } for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) if(map[i][j] == -1) map[i][j] = dist(point[i], point[j]) / walkv; for(int k = 0; k < n; ++k) for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) map[i][j] = min(map[i][j], map[i][k] + map[k][j]); printf("%.0f\n", map[0][1]); return 0; }
相关文章推荐
- 关于进程和线程比较好的一个解释
- 使用C#详解常用排序算法(一):概述
- Python classmethod staticmethod 进价学习
- 可以改变命运的八个途径
- 什么是堆栈?
- 黑马程序员---OC autorelease
- UVA - 10972 RevolC FaeLoN (边双连通分量)
- poj 1088 滑雪【记忆化搜索】
- 8月9日,牢骚第一阶段 暑假一期计划
- 有哪些高效但是不常见的Linux命令?
- Proguard returned with error code 1. see console
- 六足机器人的实现原理
- python 按照list中的dic的某key排序
- Log4J简易配置
- 剑指Offer面试题32(java版):从1到n整数中1出现的次数
- IIS发布ASP.NET MVC4.0教程
- Scala中Curring实战详解之Scala学习笔记-16
- Linux下批量修改文件名
- php安装mysql扩展,版本不一致的解决办法
- GPS定位原理