模板题目,需要注意的是关于精度的控制
大概解题思路就是先求出来每两点之间的最短距离,之后取里面最大的一个。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 1000 + 50
#define Inf 100000008
using namespace std;
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
double dist[N][N];
double calc(double x1,double x2,double y1,double y2){
double x = x1 - x2;
double y = y1 - y2;
double dis = sqrt(x * x + y * y);
return dis;
}
int main(){
int T;
scanf("%d",&T);
for(int Case = 1;Case <= T;Case ++){
int n;
double MAX = 0;
double x[N],y[N];
scanf("%d",&n);
for(int i = 0; i < n;i ++){
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i = 0; i < n;i ++)
for(int j = 0; j < n; j ++){
double dis = calc(x[i],x[j],y[i],y[j]);
if(dis <= 10)
dist[i][j] = dis;
else
dist[i][j] = Inf;
}
for(int i = 0; i < n ;i++)
for(int j = 0; j < n; j++)
for(int k = 0; k < n; k++){
dist[j][k] = min(dist[j][i] + dist[i][k],dist[j][k]);
}
for(int i = 0; i < n ;i++)
for(int j = 0; j < n; j++)
if(i != j){
MAX = max(dist[i][j],MAX);
}
printf("Case #%d:\n",Case);
if(fabs(MAX - Inf) > 1e-4)
printf("%.4f\n\n",MAX);
else
printf("Send Kurdy\n\n");
}
return 0;
}