106 miles to Chicago
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 3931   Accepted: 1827   Special Judge

Description

In the movie "Blues Brothers", the orphanage where Elwood and Jack were raised may be sold to the Board of Education if they do not pay 5000 dollars in taxes at the Cook Country Assessor's Office in Chicago. After playing a gig in the Palace Hotel ballroom to earn these 5000 dollars, they have to find a way to Chicago. However, this is not so easy as it sounds, since they are chased by the Police, a country band and a group of Nazis. Moreover, it is 106 miles to Chicago, it is dark and they are wearing sunglasses. 
As they are on a mission from God, you should help them find the safest way to Chicago. In this problem, the safest way is considered to be the route which maximises the probability that they are not caught.

Input

The input contains several test cases. 
Each test case starts with two integers n and m (2 <= n <= 100 , 1 <= m <= n*(n-1)/2). n is the number of intersections, m is the number of streets to be considered. 
The next m lines contain the description of the streets. Each street is described by a line containing 3 integers a, b and p (1 <= a, b <= n , a != b, 1 <= p <= 100): a and b are the two end points of the street and p is the probability in percent that the Blues Brothers will manage to use this street without being caught. Each street can be used in both directions. You may assume that there is at most one street between two end points. 
The last test case is followed by a zero.

Output

For each test case, calculate the probability of the safest path from intersection 1 (the Palace Hotel) to intersection n (the Honorable Richard J. Daley Plaza in Chicago). You can assume that there is at least one path between intersection 1 and n. 
Print the probability as a percentage with exactly 6 digits after the decimal point. The percentage value is considered correct if it differs by at most 10-6 from the judge output. Adhere to the format shown below and print one line for each test case.

Sample Input

5 7
5 2 100
3 5 80
2 3 70
2 1 50
3 4 90
4 1 85
3 1 70
0

Sample Output

61.200000 percent

题目就是模板题的简单变形,平时求的是最短的路径,最少的花费啥的,这个求得是能逃脱的最大概率
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
double graph[maxn][maxn];
int visit[maxn];
double dis[maxn];
int n, m; void dijkstra()
{
for(int i = ; i <= n; ++i)
{
dis[i] = graph[][i];
}
visit[] = ;
dis[] = ; int k;
double max_s;
for(int i = ; i <= n; ++i)
{
max_s = ;
for(int j = ; j <= n; ++j)
{
if(dis[j] > max_s && !visit[j])
{
max_s = dis[j];
k = j;
}
} visit[k] = ; for(int j = ; j <= n; ++j)
if(!visit[j] && graph[k][j] * dis[k] > dis[j])
{
dis[j] = dis[k] * graph[k][j];
}
}
} int main()
{
while(cin >> n >> m)
{
if(n == || m == ) break;
int x, y;
double z;
memset(graph, , sizeof(graph));
for(int i = ; i <= m; ++i)
{
cin >> x >> y >> z;
graph[x][y] = graph[y][x] = z/;
}
memset(visit, , sizeof(visit));
dijkstra();
printf("%lf percent\n", dis[n]*);
}
return ;
}

好的就这。

 

最新文章

  1. 前端工具gulp使用
  2. table 标签
  3. 安装lua和openresty
  4. Linux常用指令---ps(查看进程)
  5. VNC+SSH相关应用
  6. vector中的erase方法[转+补充]
  7. BZOJ 2323 细胞(矩阵)
  8. 深入了解float
  9. 关闭Sql Assistant的自动智能命名别名的问题
  10. 四、 添加模型Model(ASP.NET MVC5 系列)
  11. 使用CHCA搭建静态博客
  12. python函数把可变数据类型当默认参数值的问题(转)
  13. java之路 数据类型-常量
  14. bzoj营业额统计
  15. Redis的集群模式
  16. EntityFramework 5.0 CodeFirst 教程03-数据结构的定义/列的属性
  17. jsp/servlet/mysql/linux基本概念和操作
  18. 门禁系统socket通讯编程
  19. JavaScript使用技巧精萃
  20. 【转】ssh登录原理以及ssh免密码登陆

热门文章

  1. hdu1212(大数取模)
  2. NYOJ题目842整除的尾数
  3. PHP之MVC项目实战(三)
  4. 一般处理程序获取session值
  5. EasyUi &ndash; 5.修改$.messager.show() 弹出窗口在浏览器顶部中间出现
  6. PHP面试题集
  7. 攻城狮在路上(壹) Hibernate(十三)--- Hibernate的检索方式(上)
  8. Win10 UAP 标题栏
  9. hdu 4751 2013南京赛区网络赛 二分图判断 **
  10. hdu 4293 2012成都赛区网络赛 dp ****