标签:des style c class blog code
Time Limit: 10000/5000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 6119 Accepted
Submission(s): 2178
简单题,脑抽了错了好多次:
1 //1687MS 6660K 989B G++ 2 #include<stdio.h> 3 #include<string.h> 4 #define N 1005 5 double g[N][N]; 6 int vis[N]; 7 double d[N]; 8 int n; 9 void dij(int u) 10 { 11 memset(vis,0,sizeof(vis)); 12 for(int i=1;i<=n;i++) 13 d[i]=g[u][i]; 14 vis[u]=1; 15 d[u]=1; 16 for(int i=1;i<n;i++){ 17 double temp=0; 18 int v=u; 19 for(int j=1;j<=n;j++) 20 if(!vis[j] && d[j]>temp){ 21 v=j; 22 temp=d[j]; 23 } 24 vis[v]=1; 25 for(int j=1;j<=n;j++) 26 if(!vis[j] && d[j]<g[v][j]*temp) 27 d[j]=g[v][j]*temp; 28 } 29 } 30 int main(void) 31 { 32 int m,a,b; 33 while(scanf("%d",&n)!=EOF) 34 { 35 for(int i=1;i<=n;i++) 36 for(int j=1;j<=n;j++) 37 scanf("%lf",&g[i][j]); 38 scanf("%d",&m); 39 while(m--){ 40 scanf("%d%d",&a,&b); 41 dij(a); 42 if(d[b]==0) puts("What a pity!"); 43 else printf("%.3lf\n",d[b]); 44 } 45 } 46 return 0; 47 }
hdu 1596 find the safest road (最短路径),布布扣,bubuko.com
hdu 1596 find the safest road (最短路径)
标签:des style c class blog code
原文地址:http://www.cnblogs.com/GO-NO-1/p/3735642.html