POJ----2502
来源:互联网 发布:怎样在淘宝上注册网店 编辑:程序博客网 时间:2024/06/05 22:57
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.
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 10000 200 5000 200 7000 200 -1 -1 2000 600 5000 600 10000 600 -1 -1
Sample Output
21
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#define N 330
#define INF 1e30
using namespace std;
struct node
{
double x, y;
}p[N];
double maps[N][N], dis[N];
int vis[N];
double Dist(node a, node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void dij(int n)
{
int i, j, index;
for(i=1;i<=n;i++)
{
dis[i]=maps[1][i];
vis[i]=0;
}
vis[1]=1;
for(i=1;i<=n;i++)
{
index=-1;
double Min=INF;
for(j=1;j<=n;j++)
{
if(!vis[j] && dis[j]<Min)
{
Min=dis[j];
index=j;
}
}
if(index==-1)
break;
vis[index]=1;
for(j=1;j<=n;j++)
{
if(!vis[j] && dis[j]>maps[index][j]+Min)
dis[j]=Min+maps[index][j];
}
}
printf("%.0f\n", dis[2]);
}
int main()
{
double v1=10000.0/60;
double v2=40000.0/60;
while(scanf("%lf%lf%lf%lf",&p[1].x,&p[1].y,&p[2].x,&p[2].y)==4)
{
int n=2, cot=3, x, y, i, j;
for(i=1;i<N;i++)
for(j=1;j<N;j++)
maps[i][j]=(i==j)?0:INF;
while(scanf("%d%d",&x,&y)==2)
{
if(x==-1 && y==-1)
{
cot=n+1;
continue;
}
n++;
p[n].x=x;
p[n].y=y;
if(n!=cot)
maps[n][n-1]=maps[n-1][n]=min(maps[n][n-1],Dist(p[n], p[n-1])/v2);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
maps[i][j]=min(maps[i][j], Dist(p[i], p[j])/v1);
}
}
dij(n);
}
return 0;
}
0 0
- POJ 2502
- POJ----2502
- poj 2502
- POJ 2502
- POJ 2502 Subway
- poj 2502 (为过)
- poj 2502 Subway
- POJ 2502 Dijkstra
- poj 2502Subway flody
- POJ-2502-Subway
- POJ 2502 Dijkstra
- poj 2502 Subway
- POJ 2502 Subway
- POJ 2502 Subway
- POJ 2502 Subway
- Dijkstra-POJ-2502-Subway
- poj 2502 Suwbay【floyd】
- POJ 2502 Subway
- JAVA:自定义注解
- sqlite 版本升级及数据库操作类(二)
- 一、windows 下安装并使用 lua
- poj---1847
- hibernate一对多单向关联
- POJ----2502
- Supplicant层socket与内核网口、socket的对应连接
- activity的生命周期
- CSDN-markdown快捷键及表格
- Hdu1166 敌兵布阵 线段树、单点更新
- EJB——消息和消息驱动bean(二)
- poj---1502
- Trailing Zeroes (III)(n!后有多少零+二分)
- Eclipse Memory Analyzer 使用技巧