poj 2502Subway flody

Subway
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4593 Accepted: 1497

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

//这题就是给你出发点和终点的坐标,然后要你求出怎么样用最短的时间从起点到终点,给出的是subway的坐标。最后的输入是以EOF结束。我们要考虑的就是要是相邻的两个subway就用subwaydis,要不是相邻的话, 就要考虑用步行,也就是walkdis

然后计算最短路的时候是调用flody

 

代码如下:

#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define d double
const int maxn=210; 
const int inf=1<<29; 
double map[maxn][maxn];
int n;
struct point{
	int x,y; 
}s[maxn]; 
double wal(int i,int j){
	d length=sqrt(((d)s[i].x-(d)s[j].x)*((d)s[i].x-(d)s[j].x)+((d)s[i].y-(d)s[j].y)*((d)s[i].y-(d)s[j].y));
	return 60*length/10000 ;
} 
double sub(int i,int j){
	d length=sqrt(((d)s[i].x-(d)s[j].x)*((d)s[i].x-(d)s[j].x)+((d)s[i].y-(d)s[j].y)*((d)s[i].y-(d)s[j].y));
	return 60*length/40000;
} 
void flody(){
	for(int k=1;k<=n;k++){
		for (int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){ 
				map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
			} 
		} 
	} 
}
int main(){ 
	scanf("%d%d%d%d",&s[1].x,&s[1].y,&s[2].x,&s[2].y);
	map[1][2]=map[2][1]=wal(1,2);
	n=3;
	int j=0,a,b ;
	while(scanf("%d%d",&a,&b)!=EOF){
		if(a==-1&&b==-1) 
			j=0;
		else{ 
			s[n].x=a,s[n].y=b;
			for(int i=1;i<n-j;i++){ 
				map[i][n]=map[n][i]=wal(i,n);
			} 
			for(int i=n-j;i<n;i++){
				map[i][n]=map[n][i]=sub(i,n);
			}
			j=1,n++; 
		} 
	} 
	n--; 
	flody();
	printf("%.0f\n",map[1][2]); 
	return 0;
}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值