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. 【Latex】如何在Latex中插入伪代码 —— clrscode3e

    1. 简介clrscode3e是<算法导论(第三版)>使用的伪代码的宏包,clrs其实表示的是Cormen.Leiserson.Rivest和Stein.它有个更老的版本clrscode, ...

  2. 查看mssql死锁的详细信息(存储过程)

    CREATE  procedure [dbo].[sp_who_lock]asbegindeclare @spid int,@bl int,        @intTransactionCountOn ...

  3. Unique Encryption Keys (思维题 预处理)

    题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; ...

  4. POJ 1276 (多重背包) Cash Machine

    题意: 有n种纸币,已知每种纸币的面值和数量,求所能凑成的不超过cash的最大总面值. 分析: 这道题自己写了一下TLE了,好可耻.. 找了份比较简洁的代码抄过来了..poj1276 #include ...

  5. bzoj1934: [Shoi2007]Vote 善意的投票

    最大流..建图方式都是玄学啊.. //Dinic是O(n2m)的. #include<cstdio> #include<cstring> #include<cctype& ...

  6. ASP.NET MVC从客户端中检测到有潜在危险的 Request.Form 值

    ASP.NET MVC4(Razor)从客户端中检测到有潜在危险的 Request.Form 值 “/”应用程序中的服务器错误. 从客户端(Content=" sdfdddd ...&quo ...

  7. 待实践三:MVC3下 路由的测试 使用 RouteDebug.dll 来测试判断路由是否符合

    在需要进行测试路由是否匹配的项目中引用    RouteDebug.dll   并且在MVC的Global.asax里面加入一段代码   //下面这行代码一定是在 RegisterRoutes(Rou ...

  8. hdu 4690 EBCDIC

    还有什么好说的呢?打表题= = #include<cstdio> #include<cstring> #include<algorithm> #include< ...

  9. 分享一段H264视频和AAC音频的RTP封包代码

    1. H264视频的RTP封包 static int h264_parse(Track *tr, uint8_t *data, size_t len) { h264_priv *priv = tr-& ...

  10. Buffer cache 的调整与优化

    Buffer cache 的调整与优化 -============================== -- Buffer cache 的调整与优化(一) --==================== ...