【POJ 2253 Frogger】+ Floyd
来源:互联网 发布:企业网站域名备案表 编辑:程序博客网 时间:2024/05/17 23:00
Frogger
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 38887 Accepted: 12521
Description
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
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) 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
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
2
0 0
3 4
3
17 4
19 4
18 5
0
Sample Output
Scenario #1
Frog Distance = 5.000
Scenario #2
Frog Distance = 1.414
题意 : 求青蛙从 1 点跳到 2 点的过程中至少需要跳的最近距离:
思路 : floyd 算法,如果在两个石头中加入第三个石头后,需要跳的最远的距离小于原来需要跳的距离,者把该点作为一个中间点
AC代码 :
#include<cstdio>#include<cmath>#include<algorithm>using namespace std;struct node{ double a,b;}st[210];double vis[210][210];void floyed(int n){ for(int k = 1 ; k <= n ; k++) for(int i = 1 ; i <= n - 1 ; i++) for(int j = i + 1 ; j <= n ; j++) if(vis[i][k] < vis[i][j] && vis[j][k] < vis[i][j]) if(vis[i][k] < vis[j][k]) vis[i][j] = vis[j][i] = vis[j][k]; else vis[i][j] = vis[j][i] = vis[i][k];}int main(){ int nl = 0,n; while(scanf("%d",&n) != EOF){ if(n == 0) break; for(int i = 1 ; i <= n ; i++) scanf("%lf %lf",&st[i].a,&st[i].b); for(int i = 1 ; i <= n - 1; i++) for(int j = i + 1 ; j <= n ; j++){ double va = st[i].a - st[j].a,vb = st[i].b - st[j].b; vis[i][j] = vis[j][i] = sqrt(va * va + vb * vb); } floyed(n); printf("Scenario #%d\n",++nl); printf("Frog Distance = %.3lf\n\n",vis[1][2]); } return 0;}
- POJ 2253 Frogger Floyd
- 【Floyd】-POJ-2253-Frogger
- Frogger poj 2253 floyd
- poj 2253 Frogger (floyd)
- poj 2253 Frogger (floyd)
- POJ-2253 Frogger (Floyd)
- POJ 2253 Frogger 【Floyd】
- 【POJ 2253 Frogger】+ Floyd
- POJ 2253 Frogger (Floyd)
- POJ 2253 Frogger (floyd, 二分)
- POJ 2253 Frogger(Floyd)
- poj 2253 Frogger (spfa) (Floyd)
- poj 2253 Frogger【Dijkstru&&floyd】
- POJ-2253 Frogger(Dijkstra)(Floyd)
- POJ 2253 Frogger(floyd算法)
- POJ 2253 Frogger (Floyd)
- poj 2253 Frogger(floyd)
- poj 2253 Frogger(floyd变形)
- mysql5.7忘记root密码以及授权远程访问解决方案
- Java 面向对象(一)
- mkdir -p命令
- servlet和jsp有什么关系
- 二次规划(quadratic programming)
- 【POJ 2253 Frogger】+ Floyd
- maven自定义插件 jenkis打包 jar包版本校验dependency-check-plugin:check
- Docker 使用指南 (四)—— 数据卷的使用
- hdu 5451 Best Solver -广义斐波那契+矩阵快速幂+共轭构造+循环节
- 链表尾插
- SAP 标准成本、计划成本、目标成本、实际成本计算公式
- Windows下使用TensorFlow
- Android Studio运行找不到Genymotion虚拟机
- C++中的new和delete,C中的free、malloc、calloc、realloc、_alloca