Description
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
Output
Sample Input
20 03 4317 419 418 50Sample Output
Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414
#include<stdio.h>
#include<math.h>
#include<string.h>
int idx=1,n;
float x[1001],y[1001];
float f[1001][1001];
int min(float a,float b)
{
if(a<b)
return a;
return b;
}
int max(float a2,float b2)
{
if(a2>b2)
return a2;
return b2;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n!=0)
{
for(int i=1;i<=n;i++)
scanf("%f%f",&x[i],&y[i]);
memset(f,0x3f,sizeof(f));
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=min(f[i][j],max(f[i][k],f[k][j]));
printf("Scenario #%d\n",idx);
idx++;
printf("Frog Distance = %.3f\n",sqrt(f[1][2]));
printf("\n");
}
else
return 0;
}
}
AC 頂一個