poj 2502 floyd 家-地铁站-学校
来源:互联网 发布:常熟090淘宝 编辑:程序博客网 时间:2024/04/20 20:59
题意:给出家和学校的坐标,从家出发,沿途经过地铁站,一些地铁站是一条线上的,可以如果到地铁站的话,可以随便上车,步行和地铁的速度也给出,求家到学校的最短时间。
注意:地铁线不一定是直的,所以只要在一条地铁线并且是相邻的两站那么就建乘地铁的边,否则就步行。
思路:建图+floyd
#include<iostream>#include<cmath>#define INF 0x7ffffffusing namespace std;struct point{ int x,y; int ans;}P[210];double get_dist(int i,int j){ return sqrt(double((P[i].x-P[j].x)*(P[i].x-P[j].x)+(P[i].y-P[j].y)*(P[i].y-P[j].y)));}double dist[210][210];int main(){ point start,end; //freopen("data.txt","r",stdin); //freopen("shuchu.txt","w",stdout); scanf("%d%d%d%d",&start.x,&start.y,&end.x,&end.y); P[0].x=start.x;P[0].y=start.y; P[0].ans=0; int tx,ty,h=1,line=1,i,j,k,m=0; while(scanf("%d%d",&tx,&ty)!=EOF) { //if(line==3) break; if(tx==-1&&ty==-1) {line++;continue;} P[h].x=tx;P[h].y=ty; P[h].ans=line; h++; } P[h].ans=line; P[h].x=end.x; P[h].y=end.y;//输入完毕 for(i=0;i<=h;i++) { for(j=i+1;j<=h;j++) { if(P[i].ans==P[j].ans&&j-i==1)//相邻地铁线需要的时间 { dist[i][j]=dist[j][i]=get_dist(i,j)/(40000/60.0); } else dist[i][j]=dist[j][i]=get_dist(i,j)/(10000/60.0);//不相邻的话,不能够直接建图,只能步行、 } } for(i=0;i<=h;i++) dist[i][i]=0;//建图 for(k=0;k<=h;k++) for(i=0;i<=h;i++) for(j=0;j<=h;j++) if(dist[i][k]+dist[k][j]<dist[i][j]) dist[i][j]=dist[i][k]+dist[k][j]; printf("%d\n",int(dist[0][h]+0.5)); //system("pause");}
- poj 2502 floyd 家-地铁站-学校
- poj 2502 Suwbay【floyd】
- 地铁站的小提琴家
- 利用Google map API 查询出当前地址的周边信息(学校,餐厅,地铁站,公交站等等)
- POJ 2502 Subway(Floyd单源最短路)
- POJ 2502 Subway 最短路 Floyd
- POJ 2502 (Dij Floyd Ballman-Ford)
- java实现floyd统计天津地铁的站点距离
- 地铁站问题
- 地铁
- POJ 1847 Floyd应用
- poj 1125 floyd算法
- POJ 2240 Arbitrage (Floyd)
- POJ 1125 Frogger (Floyd)
- poj 2240Arbitrage(Floyd)
- 【floyd】poj 3615
- POJ 2240 Arbitrage Floyd
- POJ 2253 Frogger Floyd
- 实现带题头的TextBox和PasswordBox
- Using OpenWRT on TP-Link WR841N-V7.2 router
- EWSD常用状态解释
- android中dip、dp、px、sp和屏幕密度
- HDU 2093
- poj 2502 floyd 家-地铁站-学校
- css中hideFocus的用法(去除鼠标点击时的虚线)
- ORIG1和ORIG2的运用
- 用JAVA代码备份ORACLE数据库
- Ext中的事件机制
- 采集时保持登录状态
- 野狼1.0客户端
- fedpra 16 之 samba + vsftp + nfs 配置
- 视觉中国的NoSQL之路:从MySQL到MongoDB