Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9259 Accepted Submission(s): 3273
3 1 0.5 0.5 0.5 1 0.4 0.5 0.4 1 3 1 2 2 3 1 3
0.500 0.400 0.500
<span style="font-size:12px;">#include<cstdio> #include<cstring> #define max 1010 int n; double map[max][max]; void dijkstra(int u,int v) { int visit[max]; int i,j,next=u; double dis[max],min;//注意min要用double型,用int型,导致精度缺失,wa了一次 memset(visit,0,sizeof(visit)); for(i=1;i<=n;++i) dis[i]=map[u][i]; visit[u]=1; for(i=1;i<=n;++i) { min=0; for(j=1;j<=n;++j) { if(!visit[j]&&dis[j]>min)//找最大的 { next=j; min=dis[j]; } } visit[next]=1; for(j=1;j<=n;++j) { if(!visit[j]&&dis[j]<dis[next]*map[next][j])//注意这里是乘 ,且找安全系数最大的 dis[j]=dis[next]*map[next][j]; } } if(dis[v]==0) printf("What a pity!\n"); else printf("%.3lf\n",dis[v]); } int main() { int i,j,m,u,v; double safe; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;++i) { for(j=1;j<=n;++j) { scanf("%lf",&safe); map[i][j]=safe; } } scanf("%d",&m); while(m--) { scanf("%d%d",&u,&v); dijkstra(u,v); } } return 0; }</span>