思路:

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

实现:

 #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. Ubuntu 16.04无法在WPS中输入中文的问题解决

    1. sudo gedit /usr/bin/wps 增加 export XMODIFIERS="@im=fcitx" export QT_IM_MODULE="fcit ...

  2. JFinal Weixin 微信极速 SDK

    原文:https://git.oschina.net/jfinal/jfinal-weixin

  3. [Spring] Bean Scope Singleton cs Prototype

    We can define a class to be Singleton or Prototype. If the class was defined as Prototype, then ever ...

  4. 【Unix编程】C/C++获取目录下文件或目录

    在Unix/Linux系统中,要获取一个指定目录下所有的文件或文件夹,一般用dirent.h(POSIX标准定义的目录操作头文件). 一.数据类型 在头文件<dirent.h>中定义了两种 ...

  5. HTML5----CSS3图片滤镜(filter)特效

    支持Chrome: 暂不支持浏览器:FF,IE... 希望后者努力 效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFteXM=/font/5a ...

  6. debug 和release 的区别

    http://blog.csdn.net/h_wlyfw/article/details/26688677

  7. [办公自动化]如何将PPT转为PDF,免费

    同事需要把PPT格式的文档转为PDF.她没有安装adobe acrobat,安装了微软office 2007. 这个其实可以通过安装微软官方插件来解决.无需额外费用. 所需软件为: 2007 Micr ...

  8. ugc pgc ogc web2.0 mgc

    http://yjy.people.com.cn/n/2014/0120/c245079-24169402.html machine

  9. sql 2005 win7 64 数据引擎

    有个箭头,下拉,选择服务器名(就是本机的名称),如果没有就选择浏览更多,看能搜索出不还没的话就手动输入localhost

  10. Android 录音和摄像头权限适配【转】

    本文转载自:http://blog.csdn.net/self_study/article/details/52965045 最近在研究权限适配的相关内容,整理以前的权限博客如下:  android ...