Frogger UVA 534(最小瓶颈路+floyd算法)
来源:互联网 发布:软件是怎么设计的 编辑:程序博客网 时间:2024/05/02 03:48
Frogger
From:UVA, 534
Submit
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input Specification
The input file will contain one or more test cases. The first line of each test case will contain the number of stones n ( ). The next n lines each contain two integers xi, yi ( ) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.Output Specification
For each test case, print a line saying ``Scenario #x" and a line saying ``Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.Sample Input
20 03 4317 419 418 50
Sample Output
Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414
题目大意:
有两只青蛙,在两块不同的石头上,有一只想要去拜访另一只,要求通过它石头进行跳跃然后在一起呀在一起,可想而知,由于石头有很多,他们中间的路径也有很多,现在要求求一个长度:从每条路径里面挑出那步跨越最大的,然后从这些跨越最大的里面挑出最小的。
解题思路:
Floyd-warshall算法。
代码:
#include<iostream>#include<cstdio>#include<cmath>using namespace std;struct node{ int x,y; node(int x0=0,int y0=0){x=x0,y=y0;}}stone[1<<9];int n,t=0;double dis[1<<9][1<<9],l,r;//快bool con[1<<9][1<<9];void input(){ for(int i=0;i<n;i++) cin>>stone[i].x>>stone[i].y;}double distanse(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void solve(){ l=0,r=1e5; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ dis[i][j]=distanse(stone[i],stone[j]); } } while(r-l>=1e-5){//写成这种形式的 double mid=(l+r)/2; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(dis[i][j]>mid) con[i][j]=false;//在原图中删去所有边长大于mid的边。 else con[i][j]=true; } } for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ con[i][j] |= con[i][k]&con[k][j];//在边长不超过mid的情况下计算可达的标志con矩阵。 } } } if(con[0][1]) r=mid;//若节点0(起点)到1(终点)的边长不超过mid,则最长边的最小值在左区间 else l=mid;//否则在右区间 }}void outResult(){ printf("Scenario #%d\nFrog Distance = %.3lf\n\n",++t,r);}int main(){ while(cin>>n&&n){ input(); solve(); outResult(); } return 0;}
- Frogger UVA 534(最小瓶颈路+floyd算法)
- UVa 534 Frogger (最小瓶颈路)
- UVA 534Frogger 【最小瓶颈树】
- UVA 10457 ,uva10048 kruskal,最小瓶颈树,floyd
- uva 534 - Frogger(最小生成树)
- POJ 2253 Frogger(floyd算法)
- uva 11354 bond 最小瓶颈路
- UVA 10457 - Magic Car(最小瓶颈路)
- Uva 534 - Frogger
- UVa 534 - Frogger
- poj 2253 Frogger (floyd算法)
- POJ2253 Frogger(floyd最短路算法)
- UVA 11354 Bond 瓶颈路 最小生成树+LCA类似
- UVA 544 - Heavy Cargo(最小瓶颈路)
- UVA 10457 Magic Car——最小瓶颈路
- UVA 567 Floyd算法
- UVA 247 Floyd算法
- UVA 534 - Frogger(kruskal扩展)
- 我反对你,正是对你的支持
- i os 转屏API的改变
- 高佳程自我总结了一下,想了挺久,我是这样的程序员
- highgui.h备查
- Cocos2d-X中的CCAction
- Frogger UVA 534(最小瓶颈路+floyd算法)
- RabbitMQ学习之Headers交换类型(java)
- NSURLConnection 同步异步HTTPRequest
- 围猎深度学习
- 摄像头参数查看与调节
- NSURLConnection下载显示进度
- 互联网世界的“人工智能”——探秘“深度学习”的前世今生
- 自己在编程工作中,还是需要学习,我自己的能力总结
- 多线程(一)