106 miles to Chicago SPOJ
来源:互联网 发布:数据整合平台 编辑:程序博客网 时间:2024/06/05 07:53
106 miles to Chicago
SPOJ - CHICAGOIn the movie "Blues Brothers", the orphanage where Elwood and Jake were raised may be sold to the Board of Education if they do not pay 5000 dollars in taxes at the Cook County 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 Specification
The input file 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 integersa, 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 Specification
For each test case, calculate the probability of the safest path from intersection1 (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 intersection1 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
The safest path for the sample input is 1 -> 4 -> 3 -> 5
这里只不过不是相加了,而是相乘找最大的
code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;double mp[105][105];int n,m;int vis[105];double dis[105];void dijkstra(){ memset(vis,0,sizeof(vis)); int i,j; for(i = 1; i <= n; i++){ dis[i] = mp[1][i]; } for(i = 1; i < n; i++){ double maxp = 0; int u = -1; for(j = 1; j <= n; j++){ if(!vis[j]&&dis[j] > maxp){ maxp = dis[j]; u = j; } } if(u == -1)break; vis[u] = 1; for(j = 1; j <= n; j++){ if(!vis[j]&&dis[u]*mp[u][j]>dis[j]){ dis[j] = dis[u]*mp[u][j]; } } } printf("%.6f percent\n",dis[n]*100);}int main(){ while(cin >> n){ if(n == 0)break; cin >> m; int i; memset(mp,0,sizeof(mp)); for(i = 0; i < m; i++){ int a,b; double p; cin >> a >> b >> p; mp[a][b] = p/100.0; mp[b][a] = p/100.0; } dijkstra(); } return 0;}
- 106 miles to Chicago SPOJ
- 106 miles to Chicago
- POJ2472 106 miles to Chicago
- toj2134 106 miles to Chicago
- poj 2472 106 miles to Chicago
- POJ 2472 106 miles to Chicago
- zoj - 2797 - 106 miles to Chicago
- Hoj 2047 106 miles to Chicago
- ZOJ 2797 106 miles to Chicago
- POJ:2472 106 miles to Chicago
- poj 2472 106 miles to Chicago
- poj 2472 106 miles to Chicago
- POJ 2472 106 miles to Chicago
- POJ-2472 106 miles to Chicago
- POJ 2472:106 miles to Chicago
- POJ 2472 106 miles to Chicago
- poj 2472 106 miles to Chicago
- 106 miles to Chicago 2010.3.6
- 京东商城分类实现
- Centos7更换yum源
- Navicat工具导出mySQL数据库某个视图结构的.sql脚本
- android 常用权限和依赖
- leetcode 94|144|145. Binary Tree Traversal 二叉树三种遍历
- 106 miles to Chicago SPOJ
- Linux 安装java环境
- Java多线程工具包java.util.concurrent---CountDownLatch
- class.getResource()和URL的getPath()分别作了什么
- fatal error C1083: 无法打开包括文件: “stddef.h”: No such file or directory
- jvm垃圾回收
- 换肤方案[整理]
- 有关二叉树的递归算法
- 排序算法-堆排序