若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1121: Problem B: Subway

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,474

题目描述

Problem B: Subway
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 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 is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.

输入

暂无

输出

暂无

样例输入

0 0 10000 1000
0 200 5000 200 7000 200 -1 -1 
2000 600 5000 600 10000 600 -1 -1

样例输出

21

参考代码

#include <stdio.h>
#include <math.h>
double z, x[203], y[203], d[202][202];
int i,j,k,n;
main() 
{
    for (i=0;i<202;i++) for (j=0;j<202;j++) d[i][j] = 1e99;
    n=2;
    scanf("%lf%lf",&x[0],&y[0]);
    scanf("%lf%lf",&x[1],&y[1]);
    while(1) 
    {
        if (2 != scanf("%lf%lf",&x[n],&y[n])) break;
        n++;
        while(1) 
        {
            scanf("%lf%lf",&x[n],&y[n]);
            if (x[n] < 0) break;
            z = hypot(x[n]-x[n-1],y[n]-y[n-1]);
            if (z < d[n-1][n]) d[n-1][n] = d[n][n-1] = z;
            n++;
        }
    }
    for (i=0;i<n;i++) for (j=0;j<n;j++) 
    {
        if (d[i][j] > 1e98) d[i][j] = 4*hypot(x[i]-x[j], y[i]-y[j]);
    }
    for (i=0;i<n;i++) for (j=0;j<n;j++) for (k=0;k<n;k++) 
    {
        if (d[j][i]+d[i][k] < d[j][k]) d[j][k] = d[j][i]+d[i][k];
    }
    printf("%0.0lfn",d[0][1]/40000*60);
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Skip Dreams孤独患者 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist