博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2472106 miles to Chicago
阅读量:7067 次
发布时间:2019-06-28

本文共 3694 字,大约阅读时间需要 12 分钟。

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 75 2 1003 5 802 3 702 1 503 4 904 1 853 1 700

Sample Output

61.200000 percent 题目就是模板题的简单变形,平时求的是最短的路径,最少的花费啥的,这个求得是能逃脱的最大概率
1 #include 
2 #include
3 #include
4 #include
5 6 using namespace std; 7 const int maxn = 110; 8 const int inf = 0x3f3f3f3f; 9 double graph[maxn][maxn];10 int visit[maxn];11 double dis[maxn];12 int n, m;13 14 void dijkstra()15 {16 for(int i = 2; i <= n; ++i)17 {18 dis[i] = graph[1][i];19 }20 visit[1] = 1;21 dis[1] = 1;22 23 int k;24 double max_s;25 for(int i = 2; i <= n; ++i)26 {27 max_s = 0;28 for(int j = 1; j <= n; ++j)29 {30 if(dis[j] > max_s && !visit[j])31 {32 max_s = dis[j];33 k = j;34 }35 }36 37 visit[k] = 1;38 39 for(int j = 1; j <= n; ++j)40 if(!visit[j] && graph[k][j] * dis[k] > dis[j])41 {42 dis[j] = dis[k] * graph[k][j];43 }44 }45 }46 47 int main()48 {49 while(cin >> n >> m)50 {51 if(n == 0 || m == 0) break;52 int x, y;53 double z;54 memset(graph, 0, sizeof(graph));55 for(int i = 1; i <= m; ++i)56 {57 cin >> x >> y >> z;58 graph[x][y] = graph[y][x] = z/100;59 }60 memset(visit, 0, sizeof(visit));61 dijkstra();62 printf("%lf percent\n", dis[n]*100);63 }64 return 0;65 }
View Code

好的就这。

 

转载于:https://www.cnblogs.com/ya-cpp/p/3859033.html

你可能感兴趣的文章
iOS开发工具——网络封包分析工具Charles
查看>>
蒙哥玛利模幂算法
查看>>
龙威零式_团队项目例会记录_14
查看>>
YAFFS2文件系统分析(转)
查看>>
获取GET/POST提交的数据,并处理中文问题
查看>>
jdbc 获取connection 对象的三种方式
查看>>
jsp标签+jstl
查看>>
第二阶段个人总结09
查看>>
FATAL ERROR: Could not find ./bin/my_print_defaults的解决办法
查看>>
文摘《十一》
查看>>
jquery 笔记。。。——》摘自武方博
查看>>
一个夭折,
查看>>
C#开发微信门户及应用(1)--开始使用微信接口(转)
查看>>
Kali-linux使用社会工程学工具包(SET)
查看>>
ScriptManager(脚本控制器)
查看>>
Android chromium 2
查看>>
poj_3468,线段树成段更新
查看>>
什么是mybatis?
查看>>
【算法导论】学习笔记——第6章 堆排序
查看>>
NS3编译运行
查看>>