POJ 2502 Subway

Subway

Time Limit: 1000ms
Memory Limit: 65536KB
This problem will be judged on  PKU. Original ID: 2502
64-bit integer IO format: %lld      Java class name: Main
 
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

 
解题:最短路,随便搞啦,反正点不多
 
 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 #include <vector>
 5 using namespace std;
 6 const int maxn = 500;
 7 struct Point{
 8     int x,y;
 9     Point(int a = 0,int b = 0){
10         x = a;
11         y = b;
12     }
13 };
14 vector<Point>p;
15 const double speed[2] = {10000.0/60.0,40000.0/60.0};
16 double calc(int a,int b,double v){
17     double tmp = (p[a].x - p[b].x)*(p[a].x - p[b].x);
18     tmp += (p[a].y - p[b].y)*(p[a].y - p[b].y);
19     return sqrt(tmp)/v;
20 }
21 double d[maxn][maxn];
22 int main(){
23     int x,y;
24     scanf("%d%d",&x,&y);
25     p.push_back(Point(x,y));
26     scanf("%d%d",&x,&y);
27     p.push_back(Point(x,y));
28     for(int i = 0; i < maxn; ++i)
29         for(int j = 0; j < maxn; ++j)
30             d[i][j] = i == j?0:-1;
31     int pre = -1;
32     while(~scanf("%d%d",&x,&y)){
33         if(x == -1 && y == -1) {pre = -1;continue;}
34         p.push_back(Point(x,y));
35         int sz = p.size();
36         if(pre != -1) d[sz-2][sz-1] = d[sz-1][sz-2] = calc(sz-2,sz-1,speed[1]);
37         pre = x;
38     }
39     int sz = p.size();
40     for(int i = 0; i < sz; ++i)
41         for(int j = 0; j < sz; ++j)
42             if(d[i][j] == -1) d[i][j] = calc(i,j,speed[0]);
43     for(int k = 0; k < sz; ++k)
44         for(int i = 0; i < sz; ++i)
45             for(int j = 0; j < sz; ++j)
46                 if(d[i][k]!=-1&&d[k][j]!=-1)
47                     d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
48     printf("%.0f\n",d[0][1]);
49     return 0;
50 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4668486.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值