poj2502 SubWay

题意:首先给你两个坐标,一个是你家里的坐标,一个是你学校的坐标,然后接下来有若干条地铁线,一行为一条地铁线,每条地铁线上有若干个站点,给出每个站点的坐标,这个距离的单位是米,现在告诉你走路是10km/h,做地铁的话是40km/h,问你从家里到学校所花费的最短时间(分钟)

思路:首先先把单位统一为m/min,因为地铁给的距离是米,并且输出的答案为分钟数,10km/h=10000/60 (m/min)

40km/h = 40000 / 60 (m/min),地铁连接的按地铁速度连边,其他都按步行速度连边。然后就是套模板了

Trick:地铁相邻的站的速度才是40 Km/h,比如站一到站二,站一到站三并不是



#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 305
#define LL long long
int cas=1,T;
struct Node
{
	double x,y;
}node[maxn];
double dist(Node a,Node b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int n;
const double INF = 1<<29;
bool vis[maxn];
double d[maxn];
double mapp[maxn][maxn];
void dijkstra(int s)
{
    for (int i = 1;i<=n;i++)
		d[i]=INF;
	memset(vis,0,sizeof(vis));
	d[s]=0;
	for (int i = 1;i<=n;i++)
	{
		int u=0;
		double mins = INF;
		for (int j = 1;j<=n;j++)
		   if (!vis[j] && d[j]<mins)
		   {
			   mins = d[j];
			   u=j;
		   }
        if (u==0)
			break;
		vis[u]=1;
		for (int j = 1;j<=n;j++)
			if (!vis[j] && d[j]>d[u]+mapp[u][j])
				d[j]=d[u]+mapp[u][j];
	}
}
int main()
{
    double walk = 10000.0 / 60;
	double sub = 40000.0 / 60;
	while (scanf("%lf%lf%lf%lf",&node[1].x,&node[1].y,&node[2].x,&node[2].y)==4)
	{
	    n = 2;
		int cnt = 3;
		int x,y;
		memset(mapp,0,sizeof(mapp));
	
		for (int i = 1;i<=300;i++)
			for (int j = 1;j<=300;j++)
			{
				if (i==j)
					mapp[i][j]=0;
				else
					mapp[i][j]=INF;
			}
		while (scanf("%d%d",&x,&y)==2)
		{
			if (x==-1 && y == -1)
			{
				cnt = n+1;
				continue;
			}
			n++;
			node[n].x=x;
			node[n].y=y;
			if (n!=cnt)              //只有相邻站点才能到达
				mapp[n][n-1] = mapp[n-1][n] = min(mapp[n][n-1],dist(node[n],node[n-1])/sub);
		}
		for (int i= 1;i<=n;i++)
			for (int j = 1;j<=n;j++)
				mapp[i][j] = min(mapp[i][j],dist(node[i],node[j])/walk);
		dijkstra(1);
		printf("%d\n",(int)(d[2]+0.5));
	}
	//freopen("in","r",stdin);
	//scanf("%d",&T);
	//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}



题目

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值