POJ-2253 Frogger(floyd)

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 83767   Accepted: 25363

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

Source

Ulm Local 1997   题意大概是求一条路径,使这条路径上的最大边最小(怎么听起来有点二分的感觉)(这个答案肯定是某一条边的长度,而且n的数据范围很小,所以不用二分做了) n的数据范围很小可以考虑用floyd的O(n3)算法 注意:floyd三层循环最开始应该枚举松弛的中间节点!!!这样避免松弛的先后顺序产生的影响!!! 这题因为精度问题G++过不了C++能过就离谱
 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <queue>
 6 #include <stack>
 7 #include <vector>
 8 #include <iostream>
 9 #include "algorithm"
10 using namespace std;
11 const int MAX=205;
12 int n,cas;
13 int xx[MAX],yy[MAX];
14 double f[MAX][MAX];
15 double dis(int i,int j){
16     return sqrt((xx[i]-xx[j])*(xx[i]-xx[j])*1.0+(yy[i]-yy[j])*(yy[i]-yy[j])*1.0);
17 }
18 int main(){
19     freopen ("frogger.in","r",stdin);
20     freopen ("frogger.out","w",stdout);
21     int i,j,k;
22     while (~scanf("%d",&n)&&n!=0){
23         for (i=1;i<=n;i++)
24             scanf("%d%d",xx+i,yy+i);
25         memset(f,0,sizeof(f));
26         for (i=1;i<=n;i++)
27             for (j=i+1;j<=n;j++)
28                 f[i][j]=f[j][i]=dis(i,j);
29         for (k=1;k<=n;k++)//第三点最先循环 
30             for (i=1;i<=n;i++)
31                 for (j=1;j<=n;j++)
32                     f[i][j]=min(f[i][j],max(f[i][k],f[k][j]));
33         printf("Scenario #%d\nFrog Distance = %.3lf\n\n",++cas,f[1][2]);
34     }
35     return 0;
36 }

 

上一篇:sql server关于日期函数的用法及理解


下一篇:DotNet程序汉化过程--SnippetCompiler奇葩的字符串