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 |
2个完全一样的函数一个能AC一个WA,哪位同学能看出问题来~~~OMG,WA20多次了啊~我打死也想不通啊~~~ A:这个不能过 void Dijkstra() { int mindis,i,j,u; int s[MAXN]; for(i=1;i<=N;i++) { dis[i]=map[1][i]; s[i]=0; if(i!=1&&dis[i]>0) pre[i]=1; else pre[i]=-1; } s[1]=1; for(i=2;i<=N;i++) { mindis=0; for(j=1;j<=N;j++) { if(s[j]==0&&dis[i]>mindis) { u=j; mindis=dis[j]; } } if(mindis==0) return; s[u]=1; for(j=1;j<=N;j++) { if(s[j]==0&&map[u][j]>0&&dis[u]+map[u][j]>dis[j]) { dis[j]=dis[u]+map[u][j]; pre[j]=u; } } } } B:这个能过 void Dijkstra() { int mindis,i,j,u; int s[MAXN]; for(i=1;i<=N;i++) { dis[i]=map[1][i]; s[i]=0; if(i!=1&&dis[i]>0) pre[i]=1; else pre[i]=-1; } s[1]=1; for(i=2;i<=N;i++) { mindis=0; for(j=1;j<=N;j++) { if(s[j]==0&&dis[j]>mindis) { u=j; mindis=dis[j]; } } if(mindis==0) return; s[u]=1; for(j=1;j<=N;j++) { if(s[j]==0&&map[u][j]>0&&dis[u]+map[u][j]>dis[j]) { dis[j]=dis[u]+map[u][j]; pre[j]=u; } } } } 如果看出来了请告诉我,万分感谢 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator