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 |
这题难道不是DIJ?In Reply To:WA,难道是精度问题?大家帮忙看看啊:) Posted by:Essence_me at 2005-09-03 22:08:37 > #include <stdio.h> > #include <memory.h> > #define true 1 > #define false 0 > #define I 0 > #define N 100 > > double cost[N][N]; > double dist[N],max; > int v0,v1; > > void main() > { > int final[N],i,v,w,n,m; > while(1) > { > scanf("%d",&n); > if(n==0)break; > scanf("%d",&m); > v0=0;v1=n-1; > memset(cost,0,sizeof(double)*n*n); > for(i=0;i<m;i++) > { > int x,y,rate; > scanf("%d%d%d",&x,&y,&rate); > x--;y--; > if(cost[x][y]!=0) > if(rate<cost[x][y]*100)continue; > cost[x][y]=(double)rate/100; > cost[y][x]=(double)rate/100; > } > for(v=0;v<n;v++) > { > final[v]=false; > dist[v]=cost[v0][v]; > } > final[v0] = true; > > while(1) > { > max=0; > for(w=0;w<n;w++) > { > if(!final[w]&&dist[w]>max) > { > max=dist[w]; > v=w; > } > } > final[v]=true; > if(final[v1]==true)break; > for(w=0;w<n;w++) > { > if(!final[w]&&dist[v]*cost[v][w]>dist[w]) > { > dist[w]=dist[v]*cost[v][w]; > } > } > } > printf("%.6lf percent\n",dist[v1]*100); > } > > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator