poj2253(dijstra应用)
来源:互联网 发布:java中string的split 编辑:程序博客网 时间:2024/06/08 00:11
题目链接:http://poj.org/problem?id=2253
题目意思:Freddy Frog暗恋Fiona Frog,在他们之间有n快石头,告诉你这n快石头的坐标,第一快为Freddy Frog的坐标,第n块为Finoa Frog的坐标,Freddy可以借助石头经过任何路径到达Fiona那里,问他最小的弹跳距离是多少(即最短路径中的最长边)。
注意:该题有多组测试数据,要求每组测试数据之间空一行!
代码:
#include<stdio.h>#include<math.h>#include<string.h>struct coo{ double x; double y;}st[205];double map[205][205];int flag[205];double dis[205];int N;double dist(int i,int j){double x1,y1;x1=pow(st[j].x-st[i].x,2.0);y1=pow(st[j].y-st[i].y,2.0);return sqrt(x1+y1);}double max(double a,double b){return a>b?a:b;}void dijkstra(){int i,j,u;double min1; dis[0]=0;for(i=1;i<N;i++){dis[i]=map[0][i];flag[i]=0;}flag[0]=1;for(i=1;i<N;i++){min1=10000000;for(j=1;j<N;j++){if(flag[j]==0 && dis[j]<min1){u=j;min1=dis[j];}}if(u==1)break;flag[u]=1;{for(j=1;j<N;j++){if(flag[j]==0 && dis[j]>max(dis[u],map[u][j])){ dis[j]=max(dis[u],map[u][j]);}}}}}void main(){ int i,j,k; int Case=0; while(scanf("%d",&N)!=EOF && N!=0) { Case++; for(i=0;i<N;i++) scanf("%lf%lf",&st[i].x,&st[i].y);memset(map,0,sizeof(map));k=0;for(i=0;i<N;i++){for(j=k;j<N;j++){ map[i][j]=map[j][i]=dist(i,j);} k++;}/*for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%.3lf ",map[i][j]);printf("\n");}*/dijkstra();printf("Scenario #%d\nFrog Distance = %.3lf\n\n",Case,dis[1]); }}
- poj2253(dijstra应用)
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- poj2253
- POJ2253
- POJ2253
- Graphics.h绘图
- ip classless 命令的作用
- SSH权威指南介绍
- Git on the way ,lesson 1
- 好的编码习惯
- poj2253(dijstra应用)
- 学习笔记——XPath内置函数库
- 线性表 之 链表的头插,尾插建立,及链表的长度
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- Oralce笔记(更新中...)
- AlphaAnimation
- ACM各个阶段的一些基本要求
- jQuery弹出窗口的实现
- 流程转换