Source: https://vjudge.net/problem/POJ-2253
And initially I thought it was the shortest route, but after I read the blog only to find big brothers maintain minimum maximum jump distance d with an array of ideas Dijkstra's [], stickers Gangster blog https://blog.csdn.net/duan_1998 / article / details / 73716128
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define INF 0x3f3f3f3f using namespace std; double w[205][205]; double d[205]; bool vis[205]; int n; struct node { double x,y; } no[205]; void djs() { for(int i=1;i<=n;i++) { d[i]=w[1][i]; vis[i]=0; } for(int i=1; i<=n; i++) { double m=INF; int x=-1; for(int j=1; j<=n; j++) if(!vis[j]&&d[j]<m) m=d[x=j]; if(x!=-1) { vis[x]=1;//标记 for(int j=1; j<=n; j++) if(!vis[j]&&d[j]>max(d[x],w[x][j])) d[j]=max(d[x],w[x][j]);//更新(维护)d数组 } } } int main() { int t=1; while(~scanf("%d",&n)&&n) { for(int i=1; i<=n; i++) scanf("%lf%lf",&no[i].x,&no[i].y); for(int i=1; i<=n; i++) for(int j=i; j<=n; j++) w[i][j]=w[j][i]=sqrt((no[i].x-no[j].x)*(no[i].x-no[j].x)+(no[i].y-no[j].y)*(no[i].y-no[j].y)); djs(); printf("Scenario #%d\nFrog Distance = %.3lf\n\n",t++,d[2]);//注意格式哦 } }