B - Frogger
1 #include<cstdio> 2 #include<queue> 3 #include<cmath> 4 #include<climits> 5 using namespace std; 6 7 const int maxn = 205; 8 double a[205][205],dis[205]; 9 int vis[205]; 10 11 double max(double a,double b) 12 { 13 return a>b?a:b; 14 } 15 16 void SPFA(int n) 17 { 18 queue<int> q; 19 int i,j; 20 for(i=2;i<=n;i++){ 21 dis[i]=INT_MAX; 22 vis[i]=0; 23 } 24 dis[1]=0; 25 q.push(1); 26 vis[1]=1; 27 while(!q.empty()){ 28 i=q.front(); 29 q.pop(); 30 vis[i]=0; 31 for(j=1;j<=n;j++) 32 if(dis[j]>max(dis[i],a[i][j])){ 33 dis[j]=max(dis[i],a[i][j]); 34 if(!vis[j]){ 35 q.push(j); 36 vis[j]=1; 37 } 38 } 39 } 40 } 41 int main() 42 { 43 int i,j,n,k=0,x[205],y[205]; 44 while(~scanf("%d",&n)){ 45 if(n==0) 46 break; 47 k++; 48 printf("Scenario #%d\n",k); 49 for(i=1;i<=n;i++) 50 scanf("%d%d",&x[i],&y[i]); 51 for(i=1;i<=n;i++) 52 for(j=1;j<=i;j++) 53 a[i][j]=a[j][i]=sqrt(double(x[i]-x[j])*(x[i]-x[j])+double(y[i]-y[j])*(y[i]-y[j])); 54 SPFA(n); 55 printf("Frog Distance = %.3lf\n\n",dis[2]); 56 } 57 return 0; 58 }