POJ2472106 miles to Chicago
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 3931 | Accepted: 1827 | Special Judge |
Description
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
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
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 ;
}
好的就这。
POJ2472106 miles to Chicago的更多相关文章
- POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)
题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...
- POJ 2472 106 miles to Chicago
最短路问题变形. 题意是给你一些道路,和路过时不被抓的概率. 要求找一条到达目的地时不被抓的最大概率概率. 初始 dis[]设为 1 .其余为 0 .找最大就可以. #include<cstdi ...
- ACM/ICPC 之 Floyd练习六道(ZOJ2027-POJ2253-POJ2472-POJ1125-POJ1603-POJ2607)
以Floyd解法为主的练习题六道 ZOJ2027-Travelling Fee //可免去一条线路中直接连接两城市的最大旅行费用,求最小总旅行费用 //Time:0Ms Memory:604K #in ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- 图论常用算法之一 POJ图论题集【转载】
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
随机推荐
- QRTZ_表注释
QRTZ_CALENDARS 存储Quartz的Calendar信息QRTZ_CRON_TRIGGERS 存储CronTrigger,包括Cron表达式和时区信息QRTZ_FIRED_TRIGGERS ...
- GTID复制之二
在线启用GTID,这样就不会对生产造成影响. 1.在每个Server上,执行 SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY=WARN;确保在ErrorLog中没有WARN ...
- 51nod1057(python2计算n!)
题目链接:www.51nod.com/onlineJudge/questionCode.html#!problemId=1057 思路:直接for循环呗- 代码: n = int( raw_input ...
- CLR via C#(09)-扩展方法
对于一些现成的类,如果我们想添加一些新的方法来完善功能,但是不想改变已有的封装,也不想使用派生类,那么该怎么办呢?这里我们可以使用扩展方法. 一见钟情--初识扩展 扩展方法使您能够向现有类型“添加”方 ...
- Jquery自定义扩展方法(一)
jquery是一款流行的JS框架,自定义JS方法,封装到Jquery中,调用起来也挺方便的,怎么写Jquery扩展方法那,网上翻阅了一部分代码,其实也挺简单的: 方式一: (jQuery.fn.set ...
- [LeetCode] Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...
- HDU4288 Coder(线段树)
注意添加到集合中的数是升序的,先将数据读入,再离散化. sum[rt][i]表示此节点的区域位置对5取模为i的数的和,删除一个数则右边的数循环左移一位,添加一个数则右边数循环右移一位,相当于循环左移4 ...
- Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式
当前有两个表,sgroup与sgroupuser,两者通过gKey关联,而sgroup表记录的是组,而sgroupuser记录是组中的用户,因此在sgroupuser中不一定有数据.需要使用Left ...
- js onclick="return test()"事件返回值,对有些事件,会影响默认动作的执行。如:onclick和onsubmit
onclick="return test()"事件返回值,对有些事件,会影响默认动作的执行.如:onclick和onsubmit <body> <!--事件返回值 ...
- android 入门-git之上传本地代码到github
github部分: 1.首先去github网站 上注册一个用户 2.说明 https://guides.github.com/activities/hello-world/ 2.点击 New repo ...