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
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include<cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string.h>
#include<bitset>
typedef long long ll;
using namespace std;
const double inf=0x3f3f3f3f;
//int inf = 2e7+100;
int n,m,e;
double G[2222][2222];
int vis[1111],d[1111],p[1111][1111];
double x[1111],y[1111];
double dis(double a,double b,double c,double d)
{
return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}
void floyd()
{
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
double t=G[i][k]+G[k][j];
if(G[i][j]>max(G[i][k],G[k][j]))
{
G[i][j]=max(G[i][k],G[k][j]);//每条路径的长度即为其中最大的权值,实际上就是求最短路的最大边权
}
}
}
}
}
int main()
{
int cnt=1;
while(~scanf("%d",&n),n)
{
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
G[i][j]=dis(x[i],y[i],x[j],y[j]);
}
}
floyd();
printf("Scenario #%d\n",cnt);
cnt++;
printf("Frog Distance = %.3lf\n",G[1][2]);
cout<<endl;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
#define mem(f, x) memset(f,x,sizeof(f))
#define sca(x) scanf("%d", &x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x);
#define pri(x) printf("%d\n", x)
#define prl(x) printf("%lld\n",x);
#define ll long long
const int inf=1e6;
double G[1111][1111];
int vis[1111];
double d[1111];
int T,n,flag;
struct node{
double x,y;
}e[1111];
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
void dji(int s,int en){
mem(vis,0);
for(int i=1;i<=n;i++){
d[i]=dis(e[s].x,e[s].y,e[i].x,e[i].y);
}
d[s]=0.0;
vis[1]=1;
for(int i=1;i<=n;i++){
int mi=inf,u=-1;
for(int j=1;j<=n;j++){
if(!vis[j]&&d[j]<mi){
mi=d[j];
u=j;
}
}
if(u==-1)
break;
vis[u]=1;
for(int j=1;j<=n;j++){
if(!vis[j]){
d[j]=min(d[j],max(d[u],G[u][j]));
}
}
}
printf("Scenario #%d\n",flag++);
printf("Frog Distance = %.3lf\n\n",d[en]);
}
int main()
{
flag=1;
while(cin>>n&&n){
for(int i=1;i<=n;i++){
cin>>e[i].x>>e[i].y;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
G[i][j]=dis(e[i].x,e[i].y,e[j].x,e[j].y);
}
}
dji(1,2);}
return 0;
}