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
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
复制一下别人的题意,有两只青蛙和若干块石头,现在已知这些东西的坐标,两只青蛙A坐标和青蛙B坐标是第一个和第二个坐标,现在A青蛙想要到B青蛙那里去,并且A青蛙可以借助任意石头的跳跃,而从A到B有若干通路,问从A到B的所有通路上的最大边,比如有 有两条通路 1(4)5 (3)2 代表1到5之间的边为4, 5到2之间的边为3,那么该条通路跳跃范围(两块石头之间的最大距离)为 4, 另一条通路 1(6) 4(1) 2 ,该条通路的跳跃范围为6, 两条通路的跳跃范围分别是 4 ,6,我们要求的就是最小的那一个跳跃范围,即4。
底下是Floyd解法。
基本思路很明确,首先在读入数据的时候用两点间的距离公式,算出每两点间的距离map[i][j](等于map[j][i]);
然后
void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mapp[i][j] = min(mapp[i][j],max(mapp[i][k],mapp[k][j]));
}
以k为跳板,进行n-1次松弛操作.......
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 210
double mapp[maxn][maxn];
int x[maxn],y[maxn];
int n;
double dis(double x1,double x2,double y1,double y2)
{
double ans = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
return ans;
}
void floyd()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mapp[i][j] = min(mapp[i][j],max(mapp[i][k],mapp[k][j]));
}
int main()
{
//freopen("d://test.txt","r",stdin);
int kase = 1;
while(scanf("%d", &n)!=EOF && n!=0)
{
memset(mapp,0,sizeof(mapp));
for(int i=1;i<=n;i++)
scanf("%d%d", &x[i], &y[i]);
for(int i=1;i<=n;i++)
for(int j = 1;j<=n;j++)
mapp[i][j] = mapp[j][i] = dis(x[i],x[j],y[i],y[j]);
floyd();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",kase++,mapp[1][2]);
}
return 0;
}