HDU 1596——find the safest road
来源:互联网 发布:cf手游rpk赤焰盘龙数据 编辑:程序博客网 时间:2024/05/22 02:29
最小生成树
dij算法就可解决。
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn 1005double map[maxn][maxn],dis[maxn];bool que[maxn];int main(){int n,i,j;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%lf",&map[i][j]);int t,s,e,k;double temp;scanf("%d",&t);while(t--){scanf("%d%d",&s,&e);memset(que,0,sizeof(que));for(i=1;i<=n;i++)dis[i]=map[s][i];que[s]=1;dis[s]=1;for(i=1;i<=n;i++){temp=0.0;for(j=1;j<=n;j++)if(!que[j]&&temp<dis[j]){temp=dis[j];k=j;}if(temp==0)break;if(que[e])break;que[k]=1;for(j=1;j<=n;j++)if(!que[j]&&dis[j]<dis[k]*map[k][j])dis[j]=dis[k]*map[k][j];}if(dis[e]==0.0)printf("What a pity!\n");elseprintf("%.3lf\n",dis[e]);}}return 0;}
- 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
- HDU 1596 find the safest road
- HDU 1596 find the safest road
- hdu 1596find the safest road--dijkstra
- 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
- hdu 1596 find the safest road
- hdu-1596 find the safest road
- HDU 1596 find the safest road(Dijkstra)
- C++ STL 算法列表
- Windows平台搭建Android开发环境
- 普通用户不需要密码重启机器
- 百度地图拖拽设置自定义坐标demo3个(后台添加、修改,前台显示)
- dlna
- HDU 1596——find the safest road
- C++静态函数
- Makefile详解(超级好)
- C语言简单示例(文件读写6)
- SQL语句的多种增、删
- cocos2dx中web+json+sqlite整合demo
- 初步了解 CoffeeScript
- openssl 生成v3证书
- GET和POST,有什么区别?