Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不知道哪里错了,真的纠结了好久,希望好心人帮下忙.#include<stdio.h> #include<stdlib.h> #include<iostream> #include<math.h> #include<string.h> using namespace std; int arr[505][505]; int brr[505]; int vist[505]; int INF=100000000; int n,geshu; int x,y,z; int main() { int k=1; while(scanf("%d %d",&n,&geshu)!=EOF&&n+geshu) { for(int i=0;i<n;i++) for(int j=0;j<n;j++) arr[i][j]=arr[j][i]=INF; for(int i=0;i<geshu;i++) { scanf("%d %d %d",&x,&y,&z); x--; y--; if(arr[x][y]>z) arr[x][y]=arr[y][x]=z; } printf("System #%d\n",k++); for(int i=0;i<n;i++) brr[i]=arr[i][0]; vist[0]=1; int hold; for(int i=0;i<n;i++) { int mx=INF; for(int j=0;j<n;j++) { if(!vist[j]&&brr[j]<mx); { mx=brr[j]; hold=j; } } vist[hold]=1; for(int j=0;j<n;j++) { if(!vist[j]&&brr[j]>arr[hold][j]+brr[hold]) brr[j]=arr[hold][j]+brr[hold]; } } int mx1=0; for(int i=0;i<n;i++) { if(brr[i]!=INF) { if(brr[i]>mx1) { mx1=brr[i]; hold=i; } } } int flag=1; int ex,ey; double ff=0.0; for(int i=0;i<n;i++) for(int j=0;j<n;j++) { if(ff<(double)max(brr[i],brr[j])+((double)arr[i][j]-(double)abs(brr[i]-brr[j]))/2&&arr[i][j]!=INF&&abs(brr[i]-brr[j])<arr[i][j]) { flag=0; printf("%lf\n",ff); ff=(double)max(brr[i],brr[j])+((double)arr[i][j]-(double)abs(brr[i]-brr[j]))/2; printf("%lf\n",ff); ex=i; ey=j; } } if(flag) { printf("The last domino falls after %d.0 seconds, at key domino %d.\n",mx1,hold+1); } else { printf("The last domino falls after %.1lf seconds, between key dominoes %d and %d.\n",ff,min(ex,ey)+1,max(ex,ey)+1); } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator