pku 2253

题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=2253

题目大意:找出路径中所有路径中步子的最大值的最小值。。还是Dijkstra

#include<iostream> #include<cmath> #include<stdio.h> #include<string.h> using namespace std; const int MAX=203; struct point { int x,y; }sq[MAX]; double map[MAX][MAX]; double dist[MAX]; int visit[MAX]; int n; void dijkstra() { int k; for(int i=1;i<=n;i++) dist[i]=map[1][i]; for(int j=1;j<=n;j++) { k=0; for(int i=1;i<=n;i++) if(!visit[i]) if(k==0||dist[i]<dist[k]) k=i; cout<<k<<endl; visit[k]=1; for(int i=1;i<=n;i++) if(map[k][i]>0) dist[i]=min(max(dist[k],map[k][i]),dist[i]); } } int main() { int T=0; while(scanf("%d",&n)&&n) { memset(map,0,sizeof(map)); memset(visit,0,sizeof(visit)); memset(dist,0,sizeof(dist)); for(int i=1;i<=n;i++) scanf("%d%d",&sq[i].x,&sq[i].y); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) map[i][j]=map[j][i]=(double)sqrt((sq[i].x-sq[j].x)*(sq[i].x-sq[j].x)+(sq[i].y-sq[j].y)*(sq[i].y-sq[j].y)); dijkstra(); printf("Scenario #%d/n",++T); printf("Frog Distance = %.3f/n",dist[2]); printf("/n"); } return 0; }

你可能感兴趣的:(pku 2253)