zoukankan      html  css  js  c++  java
  • 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
    ",d[0][1]);
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    微信小程序
    如何在微信小程序中使用骨架屏
    Nlog打印日志到Influxdb数据库
    C#通过模板导出Word的两种方法(超简单)
    VS2019制作的安装包,默认安装到C盘快捷方式无法打开
    orcale数据库还原备份
    Thread 类创建线程
    Quartz.NET
    DataTable ,使用详细。
    Unity3D 学习
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4668486.html
Copyright © 2011-2022 走看看