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. objectC时间用法

    #define kDEFAULT_DATE_TIME_FORMAT (@"yyyy-MM-dd HH:mm:ss") //获取当前日期,时间+(NSDate *)getCurren ...

  2. 在BSP的.bat文件下設置全局變量方法

    用于多個產品共用一個BSP的時候,在BSP的.bat文件中設置全局變量,去掉不需要加載的驅動和不同點是很好的方法. 一,舉例:BSP中.bat的一段code: set BSP_SMDK2443=1 s ...

  3. 将Ftp添加到资源管理器中直接使用

    在资源管理器中,右键,添加网络位置. 然后输入ftp的url ftp://server2008 使用匿名方式登录

  4. HDU 3492 (直线与所有线段相交) Segment

    题意: 给出n个线段,判断是否存在一条直线使得所有线段在直线上的射影的交非空. 分析: 如果我们找到一条与所有线段相交的直线,然后做一条与该直线垂直的直线,这些线段在直线上的射影就一定包含这个垂足. ...

  5. UVALive 2238 Fixed Partition Memory Management(二分完美匹配)

    题意:计算机中有一些固定大小的内存,内存越大,处理速度越快.对于一个程序,加入不同的内存空间,处理所需时间不同.现给出m个内存空间,n个程序,对于每个程序程序,有k组数据(s,t),分别表示当程序 i ...

  6. 02day1

    淘汰赛制 递推 [问题描述] 淘汰赛制是一种极其残酷的比赛制度.2^n名选手分别标号1,2,3,…,2^n-1,2^n,他们将要参加n轮的激烈角逐.每一轮中,将所有参加该轮的选手按标号从小到大排序后, ...

  7. LeetCode: divideInteger

    Title: Divide two integers without using multiplication, division and mod operator. If it is overflo ...

  8. Oracle 一次 锁表 处理小记

    同事说测试库上的一张表被锁了. 不能执行DML 操作. 锁表的准确说法应该是阻塞.之前的一遍blog里有说明: 锁 死锁 阻塞Latch 等待 详解 http://blog.csdn.net/tian ...

  9. 对Spring IoC容器实现的结构分析

    本文的目标:从实现的角度来认识SpringIoC容器. 观察的角度:从外部接口,内部实现,组成部分,执行过程四个方面来认识SpringIoC容器. 本文的风格:首先列出SpringIoC的外部接口及内 ...

  10. jQuery 制作的Tab标签切换选项卡

    基于jQuery实现的一个选项卡效果,重点体现在HTML里没有内联事件处理程序,而是定义在js文件里,做到行为与结构的分离.在实际应用过程中,只要保证选项卡模块结构代码的完整性,就可以任意添加N个同类 ...