思路:

需要注意的地方:一条地铁线路并不一定和样例描述的那样是直的;同一条线路上的两个站点步行可能更快。

实现:

 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; const int MAXN = , INF = 0x3f3f3f3f;
int sx, sy, ex, ey;
double dis[MAXN][MAXN]; struct node
{
int x, y;
};
node a[MAXN]; int square(int x)
{
return x * x;
} double cal(int i, int j)
{
return sqrt((double)square(a[i].x - a[j].x) + (double)square(a[i].y - a[j].y));
} int main()
{
int x, y;
cin >> sx >> sy >> ex >> ey;
a[].x = sx; a[].y = sy;
int tmp = , cnt = ;
for (int i = ; i < MAXN; i++)
{
for (int j = ; j < MAXN; j++)
{
dis[i][j] = INF;
}
}
for (int i = ; i < MAXN; i++) dis[i][i] = ;
while (cin >> x >> y)
{
if (x == - && y == -)
{
for (int i = tmp; i < cnt - ; i++)
dis[i][i + ] = dis[i + ][i] = cal(i, i + ) / 40.0;
tmp = cnt;
continue;
}
a[cnt++].x = x; a[cnt - ].y = y;
}
a[cnt].x = ex; a[cnt].y = ey;
for (int i = ; i <= cnt; i++)
{
for (int j = i + ; j <= cnt; j++)
{
dis[i][j] = dis[j][i] = min(dis[i][j], cal(i, j) / 10.0);
}
}
for (int k = ; k <= cnt; k++)
{
for (int i = ; i <= cnt; i++)
{
for (int j = ; j <= cnt; j++)
if (dis[i][k] + dis[k][j] < dis[i][j])
dis[i][j] = dis[i][k] + dis[k][j];
}
} cout << int(dis[][cnt] / 1000.0 * 60.0 + 0.5) << endl;
return ;
}

poj2502 Subway的更多相关文章

  1. POJ2502:Subway(最短路)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14634   Accepted: 4718 题目链接:http ...

  2. POJ-2502 Subway( 最短路 )

    题目链接:http://poj.org/problem?id=2502 Description You have just moved from a quiet Waterloo neighbourh ...

  3. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  4. POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离)

    POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) Description You have just moved from a ...

  5. POJ-2502(Dijikstra应用+最短路)

    Subway POJ-2502 这里除了直接相连的地铁站,其他图上所有的点都要连线,这里是走路的速度. 记住最后的结果需要四舍五入,否则出错. #include<iostream> #in ...

  6. 第一次作业——subway

    作业源程序代码:https://github.com/R-81/subway 作业程序使用说明:通过输入命令参数求解路线(仅支持-b,-c),根据参数得出路线后,程序不会结束,此时可输入地铁路线名(例 ...

  7. 2016 Multi-University Training Contest 1 J.Subway

    Subway Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Su ...

  8. Subway Icon Set – 306个像素完美的特制图标

    这个图标集是306个优化的像素完美,精雕细琢的图标.为这些设备进行了优化:iOS.Windows Phone.Windows 8 and BlackBerry 10,提供 PNG, SVG, XALM ...

  9. ural 1272. Non-Yekaterinburg Subway

    1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to co ...

随机推荐

  1. JSP中自动刷新

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/auto-refresh.html: 细想一个显示在线比赛分数.股市状态或当前交易额的网页.对于所有这种类 ...

  2. Google Kaptcha验证码的使用

    原文:http://www.kailing.pub/article/index/arcid/92.html Kaptcha是什么? kaptcha 是谷歌开源的非常实用的验证码生成工具,基于Simpl ...

  3. win7 多用户远程登录

    win7多用户远程登录 远程桌面服务使局域网(LAN)上的计算机可以连接到服务器(也称为远程计算机)并运行位于服务器上的程序.这可以只需要在1台机器上安装应用程序,其他机器共享使用.远程桌面连接使用远 ...

  4. Ubuntu安装JDK及环境变量配置(sun java)

    捣鼓了尽一天的时间,终于把sun的java安装上了,不是openjava了,网上试了好多的方法好多都是不可以的,所以当自己成功后就立马把方法贴出来,以方便后来者少走弯路,此文的方法绝对可行! 这里先简 ...

  5. hdu1162

    #include<cstdio> #include<cmath> #include<climits> #include<algorithm> #defi ...

  6. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation

    C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. YTU 2677: 韩信点兵

    2677: 韩信点兵 时间限制: 1 Sec  内存限制: 128 MB 提交: 61  解决: 38 题目描述 刘邦问韩信:"你觉得我可以带兵多少?"韩信:"最多十万. ...

  8. ubuntu安装wine 安装QQ

    安装最新版 wine sudo dpkg --add-architecture i386 sudo add-apt-repository ppa:wine/wine-builds sudo apt-g ...

  9. 【Codevs 3115】高精度练习之减法

    http://codevs.cn/problem/3115/ 板子题~ // <H.cpp> - Sun Oct 9 12:58:23 2016 // This file is made ...

  10. ExpandableListView的首次加载全部展开,并且点击Group不收缩、

    最近在做Android市场的应用.看到好多市场类的QQ应用宝做的算是最完美的了.在项目中要实现它的下载管理的实现,而界面如下: 反编译得到使用的是ExpandableListView.而怎么首次加载全 ...