Subway
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4928   Accepted: 1602

Description

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

 
 
 
 
人走路的速度是10km/h,地铁的速度是40km/h
题目给出一个起点,一个终点,
以及几条地铁线路运行的站点。
 
题目给的点的做坐标单位是m
把速度统一为m/min
 
答案输出从起点到终点的时间,到最近的分钟数。
 
10km/h= 10000/60 m/min
40km/h= 40000/60 m/min
 
所有的点直接以步行的速度建边。
地铁线路两站相邻的以地铁速度建边
//============================================================================
// Name : POJ.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAXN=;
struct Node
{
double x,y;
}node[MAXN];
double dis(Node a,Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
const double INF=1e30;
bool vis[MAXN];
double dist[MAXN];
double cost[MAXN][MAXN];
void Dijkstra(int n,int start)
{
for(int i=;i<=n;i++)
{
dist[i]=INF;
vis[i]=false;
}
dist[start]=;
for(int j=;j<n;j++)
{
int k=-;
double Min=INF;
for(int i=;i<=n;i++)
if(!vis[i]&&dist[i]<Min)
{
Min=dist[i];
k=i;
}
if(k==-)break;
vis[k]=true;
for(int i=;i<=n;i++)
if(!vis[i]&&dist[k]+cost[k][i]<dist[i])
dist[i]=dist[k]+cost[k][i];
}
} int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
double v1=10000.0/;
double v2=40000.0/;
while(scanf("%lf%lf%lf%lf",&node[].x,&node[].y,&node[].x,&node[].y)==)
{
int n=;
int cnt1=;
int x,y;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
if(i==j)cost[i][j]=;
else cost[i][j]=INF;
}
while(scanf("%d%d",&x,&y)==)
{
if(x==-&&y==-)
{
cnt1=n+;
continue;
}
n++;
node[n].x=x;
node[n].y=y;
if(n!=cnt1)cost[n][n-]=cost[n-][n]=min(cost[n][n-],dis(node[n],node[n-])/v2);
//只有相邻的站点能到
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cost[i][j]=min(cost[i][j],dis(node[i],node[j])/v1);
Dijkstra(n,);
// int ans=(int)round(dist[2]);
// cout<<ans<<endl;
printf("%.0lf\n",(dist[]));
}
return ;
}
 
 
 
 
 
 

POJ 2502 Subway的更多相关文章

  1. 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 ...

  2. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  3. POJ 2502 Subway(迪杰斯特拉)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Descriptio ...

  4. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  5. POJ 2502 Subway (最短路)

    Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

  6. (简单) POJ 2502 Subway,Dijkstra。

    Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...

  7. Dijkstra+计算几何 POJ 2502 Subway

    题目传送门 题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间 分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态. #include <cstdi ...

  8. POJ 2502 Subway dij

    这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...

  9. poj 2502 Subway【Dijkstra】

    <题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...

随机推荐

  1. apk反编译(5)用apktool重新生成一个未签名的apk

    用apktool反编译apk后,得到一个目录,里面有smali文件,可以对其修改,然后用apktool重新生成一个未签名的apk. 如,把smali文件中的广告部分去掉或改成自己的. 命令如下:与破解 ...

  2. Android开发之SmsManager和SmsMessage

    Android的手机功能(通话与短信)都放在android.telephony包中,到了4.4时(也就是API19)android.provider.Telephony及相关类横空出世辅助电话功能以及 ...

  3. sublime安装插件

    今天因为某些原因,把 sublime 卸载掉了,然后来安装的时候,发现 Package Control  无法安装了,或者安装好后运行 ctrl + shift + p,会报 错误,截图如下: 然后就 ...

  4. Linux 下查看文件字符编码和转换编码

    Linux 下查看文件字符编码和转换编码 如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而Linu ...

  5. dom4j修改,获取,增加xml中某个元素的属性值

    XML文件: <?xml version="1.0" encoding="UTF-8"?> <vrvscript> <item I ...

  6. HttpContext.Current.RewritePath方法重写URL

    if (!IsPostBack) { //如果请求ID为空,则重写URL为:~/index.aspx?ID=shouji.115sou.com if (Request.QueryString[&quo ...

  7. 漫谈 polling 和 Websocket

    Http被设计成了一个单向的通信的协议,即客户端发起一个request,然后服务器回应一个response.这让服务器很为恼火:我特么才是老大,我居然不能给小弟发消息... 轮询 老大发火了,小弟们自 ...

  8. 根据dwarfdump、Symbolicatecrash查找错误代码

    dSYM文件获取:1.build2.Archive 获取app UUID 命令:dwarfdump --uuid YourApp.app.dSYM 1.YourApp.app/YourApp2.You ...

  9. [反汇编练习] 160个CrackMe之017

    [反汇编练习] 160个CrackMe之017. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  10. 【策略】HDOJ-1205-吃糖果

    [题目链接:HDOJ-1205] 思路:直接看题毫无思路... 看了别人的思路,到现在还懵懵懂懂.   只要除了数目最多的糖果以外的其他所有糖果的数目之和加1(小心这里要用int64),大于等于数目最 ...