标签:input pac water spfa front http strong ems while
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 56003 | Accepted: 17617 |
Description
Input
Output
Sample Input
2 0 0 3 4 3 17 4 19 4 18 5 0
Sample Output
Scenario #1 Frog Distance = 5.000 Scenario #2 Frog Distance = 1.414
Source
1 #include<cstdio> 2 #include<cstring> 3 #include<queue> 4 #include<cmath> 5 using namespace std; 6 const int inf=1e7; 7 8 double x[206],y[206],dist[206]; 9 double mp[206][206]; 10 int n; 11 bool book[206]; 12 13 void spfa() 14 { 15 memset( book, false, sizeof book); 16 queue<int> iop; 17 iop.push(1); 18 book[1]=true; 19 dist[1]=0; 20 while( !iop.empty()){ 21 int kop=iop.front(); 22 iop.pop(); 23 for(int i=1;i<=n;i++){ 24 if(dist[i]>max( mp[kop][i], dist[kop])){ 25 dist[i]=max( mp[kop][i], dist[kop]); 26 if(!book[i]){ 27 book[i]=1; 28 iop.push(i); 29 } 30 } 31 } 32 book[kop]=0; 33 } 34 } 35 36 int main() 37 { 38 int num=1; 39 while( ~scanf("%d", &n)&&n){ 40 int top=1; 41 memset( mp, 0, sizeof mp); 42 for(int i=1;i<=n;i++){ 43 dist[i]=inf; 44 } 45 for(int i=1;i<=n;i++){ 46 scanf("%lf%lf",&x[i],&y[i]); 47 } 48 for(int i=1;i<=n;i++){ 49 for(int j=i+1;j<=n;j++) 50 mp[i][j]=mp[j][i]=sqrt((double)(x[i]-x[j ])*(x[i]-x[j])+(double)(y[i]-y[j])*(y[i]-y[j])); 51 } 52 // 53 // for(int i=1;i<=n;i++){ 54 // for(int j=1;j<=n;j++) 55 // printf("%10.3f ",mp[i][j]); 56 // printf("\n"); 57 // } 58 spfa(); 59 // for(int i=1;i<=n;i++){ 60 // printf("%10.3f ",dist[i]); 61 // } 62 // printf("\n"); 63 64 printf("Scenario #%d\nFrog Distance = %.3f\n\n",num++,dist[2]); 65 } 66 return 0; 67 }
标签:input pac water spfa front http strong ems while
原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9076310.html