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

题目大意:

有两个青蛙。在坐标系上。给你n个石头。然后问你在最短的路径上最长的那条边是多少?

分析:

先跑一遍最小生成树。

然后从1号青蛙DFS一下。就好。

注意:我也不知道为什么这道题.3lf会报错。。。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#include<cstdio> #include<string.h> #include<cmath> #include<algorithm> using namespace std; struct node{ int x,y; }point[210]; struct node_1{ int u,v; int val; }edge_all[500000]; struct node_2{ int v,next,val; }edge[500]; int head[210]; int cnt,cnt_all; int father[210]; int ans; bool cmp(node_1 a,node_1 b) { return a.val<b.val; } int find_father(int x) { return x==father[x] ? x : father[x]=find_father(father[x]); } void add_edge(int x,int y,int val) { edge[++cnt_all].v=y; edge[cnt_all].next=head[x]; edge[cnt_all].val=val; head[x]=cnt_all; return ; } int DFS(int x,int y,int max_ans) { if(x==2){ ans=max_ans; return 0; } for(int i=head[x];~i;i=edge[i].next) { if(edge[i].v!=y) { DFS(edge[i].v,x,max(max_ans,edge[i].val)); } } return 0; } int main() { int n; int t=0; while(scanf("%d",&n),n) { t++; memset(head,-1,sizeof(head)); cnt=0; for(int i=1;i<=n;++i) { scanf("%d%d",&point[i].x,&point[i].y); for(int j=1;j<i;++j) { edge_all[++cnt].u=i; edge_all[cnt].v=j; edge_all[cnt].val=((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y)); } } sort(edge_all+1,edge_all+1+cnt,cmp); cnt_all=0; for(int i=1;i<=n;++i)father[i]=i; for(int i=1;i<=cnt;++i) { int k1=find_father(edge_all[i].u); int k2=find_father(edge_all[i].v); if(k1!=k2) { add_edge(edge_all[i].u,edge_all[i].v,edge_all[i].val); add_edge(edge_all[i].v,edge_all[i].u,edge_all[i].val); father[k2]=k1; } if(cnt_all>=(n-1)*2)break; } DFS(1,0,0); printf("Scenario #%d\nFrog Distance = %.3f\n\n",t,(double)sqrt(ans)); } return 0; } |