POJ 2253
来源:互联网 发布:ubuntu 查看内核版本 编辑:程序博客网 时间:2024/06/16 21:08
参考:http://www.cnblogs.com/tanhehe/p/3169865.html
另外请参考:http://blog.csdn.net/PKU_ZZY/article/details/52434239
#include<cstdio>#include<cmath>#define N 205#define INF 1e60double max(double a,double b){return a>b?a:b;}double edge[N][N],d[N];struct Point{int x,y;}point[N];int n;bool vis[N];double dist(Point a,Point b){return sqrt( (b.y-a.y)*(b.y-a.y) + (b.x-a.x)*(b.x-a.x) );} void init(){for(int i=1;i<=n;i++){if(i==1) d[1]=0.0 , vis[1]=1;else d[i]=dist(point[1],point[i]) , vis[i]=0;for(int j=i;j<=n;j++){edge[i][j]=edge[j][i]=dist(point[i],point[j]);}}}double dijkstra(){for(int i=2;i<=n;i++){double min=INF;int x;for(int j=1;j<=n;j++) if(!vis[j] && d[j] <= min) min=d[(x=j)];//找集合Q( Q=G.V - S )里d[x]最小的那个点x vis[x]=1;//把点x放进集合S里 for(int y=1;y<=n;y++)//把在集合Q里所有与点x相邻的点都找出来松弛,因为这里青蛙可以在任意来两石头间跳,所以直接遍历 G.V - S 即可 {if(!vis[y]){double tmp = max(d[x], edge[x][y]);if(d[y] > tmp) d[y] = tmp;}}}return d[2];}int main(){int kase=0;while(scanf("%d",&n) && n!=0){for(int i=1;i<=n;i++) scanf("%d%d",&point[i].x,&point[i].y);init();printf("Scenario #%d\n",++kase);printf("Frog Distance = %.3f\n\n",dijkstra());}}
0 0
- poj-2253
- poj 2253
- poj 2253
- POJ 2253
- poj 2253
- poj 2253
- poj.2253
- poj 2253
- poj-2253
- poj 2253
- POJ 2253
- POJ 2253
- POJ 2253
- POJ 2253
- POJ 2253
- poj 2253
- poj----2253
- poj ---2253
- 2016 东莞信息特长生考试 1 子数整数
- react-native报错Could not get BatchedBridge, make sure your bundle is packaged correctly
- 开源项目导入eclipse的一般步骤
- 一篇文章搞懂人工智能、机器学习和深度学习之间的区别
- 思维 CodeForces
- POJ 2253
- 题目1153:括号匹配问题 九度OJ
- JS数组的冒泡排序法
- 2017年4月9日21:37:54 145. Binary Tree Postorder Traversal 【】hard
- Lua5.3遇到的坑
- PAT A1010. Radix PAT和牛客网全A思路以及PAT上测试例10的讨论
- Centos7 搭建 V为P屁N恩
- ava IO的File类常用方法总结三
- effective java 读书笔记---第三章对于所有对象都通用的方法