HDU 1596 find the safest road
2012-05-13 17:22
399 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1596
最短路
ps:0可以理解为那两个城市之间没有直接的通道,少看了这个条件错惨,在sx和zbw两位祖先的帮助下认清了这个问题
View Code
最短路
ps:0可以理解为那两个城市之间没有直接的通道,少看了这个条件错惨,在sx和zbw两位祖先的帮助下认清了这个问题
#include <iostream> #include <string> using namespace std; const double esp=1e-11; const int maxn=1001; int n; double Map[maxn][maxn]; double dis[maxn]; int vis[maxn]; double Dijkstra(int s,int t) { memset(vis,0,sizeof(vis)); memset(dis,0,sizeof(dis)); dis[s]=1; for(int i=0;i<n;i++) { int u; double ans=-1; for(int j=1;j<=n;j++) if(!vis[j] && dis[j]>ans) { ans=dis[j]; u=j; } vis[u]=1; if(u==t)return ans; for(int j=1;j<=n;j++) if(!vis[j] && dis[j]<Map[u][j]*dis[u]) dis[j]=Map[u][j]*dis[u]; } } int main() { while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%lf",&Map[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(Map[i][j]>1-esp&&Map[i][j]<1+esp) Map[i][j]=0; int m,s,t; scanf("%d",&m); while(m--) { scanf("%d%d",&s,&t); double ans=Dijkstra(s,t); if(ans) printf("%.3lf\n",ans); else puts("What a pity!"); } } return 0; }
View Code
相关文章推荐
- hdu 1596 find the safest road 解题报告
- hdu1596 find the safest road
- hdu1596 find the safest road
- HDU1596 find the safest road 解题报告--Dijkstra
- hdu 1596 find the safest road
- hdu-1596-find the safest road(dijkstra)
- HDU 1596 find the safest road
- 两道最短路裸题(HDU 2544 最短路 / HDU 1596 find the safest road)
- HDU 1596 find the safest road (最短路径----dijkstra)
- HDU1596 find the safest road---(最短路径dijkstra,#变形#)
- HDU 1596——find the safest road
- hdu 1596 find the safest road (最短路)
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- HDU 1596 find the safest road (spfa算法)
- HDU 1596 find the safest road
- HDU 1596 find the safest road (最短路)
- HDU1596-find the safest road
- HDU - 1596 find the safest road (最短路水题)
- HDU 1596 find the safest road
- HDU 1596 find the safest road(Dijkstra,数据格式没定义好wrong了无数发)