HDU-1596 find the safest road
2011-08-25 22:43
429 查看
最短路的变型,简单题。
刚开始竟然忘了是多组数据!!!
刚开始竟然忘了是多组数据!!!
/* * hdu-1596 find the safest road * mike-w * 2011-8-25 * --------------------- * AC 1000+ms */ #include<stdio.h> #define SIZE 1111 int n,m; double s[SIZE][SIZE]; double dist[SIZE]; int in[SIZE]; int extract(void) { int i,t; for(i=1;i<=n;i++) if(!in[i]&&dist[i]>-9999.0) break; for(t=i++;i<=n;i++) if(!in[i]&&dist[i]>dist[t]) t=i; return t>n?-1:t; } double dij(int e1,int e2) { int i,max; for(i=1;i<=n;i++) dist[i]=-9999.0,in[i]=0; dist[e1]=1.0; while((max=extract())!=e2) { if(max==-1) return -1.0; in[max]=1; for(i=1;i<=n;i++) if(!in[i]&&s[max][i]>0.0&&dist[max]*s[max][i]>dist[i]) dist[i]=dist[max]*s[max][i]; } return dist[e2]; } int main(void) { int i,j,t1,t2; double t3; #ifndef ONLINE_JUDGE freopen("1596.in","r",stdin); #endif while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%lf",s[i]+j); scanf("%d",&m); while(m-->0) { scanf("%d%d",&t1,&t2); if((t3=dij(t1,t2))>0) printf("%.3lf\n",t3); else puts("What a pity!"); } } return 0; }
相关文章推荐
- HDU 1596 find the safest road
- hdu 1596 find the safest road
- hdu-1596 find the safest road(SPFA做法)
- find the safest road HDU - 1596
- HDU 1596(find the safest road) 最短路(SPFA&FLOYD&Dijkstra)
- HDU 1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 floyd算法 find the safest road
- hdu 1596 find the safest road
- HDU 1596 find the safest road (最短路)
- HDU-1596-find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road(priority_queue )
- HDU 1596 find the safest road
- hdu 1596 find the safest road
- HDU 1596 find the safest road
- HDU 1596 find the safest road
- HDU 1596 find the safest road(SPFA)
- hdu 1596 find the safest road(最长路)
- find the safest road HDU - 1596 (spfa)