求最短路径中单次跳跃的最大值,可以使用Floyd算法求解:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 200 + 10;
const int INF = 0x3f3f3f3f;
double graph[N][N];
double x[N], y[N];
void Floyd(int n){
for(int k = 1; k <= n; k ++ ){
for(int i = 1; i < n; i ++ ){
for(int j = i + 1; j <= n; j ++ ){ //许多通路中最长边中的最小边
graph[i][j] = graph[j][i] = min(graph[i][j], max(graph[i][k], graph[k][j]));
}
}
}
}
int main(){
int n;
int caseNumber = 1;
while(scanf("%d", &n) != EOF && n){
for(int i = 1; i <= n; i ++ ) scanf("%lf%lf", &x[i], &y[i]);
memset(graph, INF, sizeof(graph));
for(int i = 1; i < n; i ++ ){
for(int j = i + 1; j <= n; j ++ ){
double x1 = x[i] - x[j];
double y1 = y[i] - y[j];
graph[i][j] = graph[j][i] = sqrt(x1 * x1 * 1.0 + y1 * y1 * 1.0);
}
}
Floyd(n);
printf("Scenario #%d\n", caseNumber ++ );
printf("Frog Distance = %.3f\n\n", graph[1][2]);
}
return 0;
}