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 ;
}

好的就这。

 

POJ2472106 miles to Chicago的更多相关文章

  1. POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)

    题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...

  2. POJ 2472 106 miles to Chicago

    最短路问题变形. 题意是给你一些道路,和路过时不被抓的概率. 要求找一条到达目的地时不被抓的最大概率概率. 初始 dis[]设为 1 .其余为 0 .找最大就可以. #include<cstdi ...

  3. ACM/ICPC 之 Floyd练习六道(ZOJ2027-POJ2253-POJ2472-POJ1125-POJ1603-POJ2607)

    以Floyd解法为主的练习题六道 ZOJ2027-Travelling Fee //可免去一条线路中直接连接两城市的最大旅行费用,求最小总旅行费用 //Time:0Ms Memory:604K #in ...

  4. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  7. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  8. 图论常用算法之一 POJ图论题集【转载】

    POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...

  9. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

随机推荐

  1. 已有a,b两个链表,每个链表中的结点包括学号,成绩。要求把两个链表合并。按学号升序排列.

    #include <stdio.h>#define SIZE sizeof(struct student)struct student{       long num;       flo ...

  2. Android 添加cookie

    /** * 添加cookie * * @param url */ private void setCookie(String url) { // 获取uid String uid = UserData ...

  3. jQuery Mobile学习之grid、等待显示的ajax效果、页面跳转、页面跳转传递参数等(二)

    Index.cshtml <!-- Start of second page --> <section data-role="page" id="bar ...

  4. Ultra-QuickSort【归并排序典型题目】

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 34470   Accepted: 12382 ...

  5. 同一服务器配置DataGuard

    实验环境:1.虚拟机VMware Server 1.0.62.操作系统:ora10g@linux5 /home/oracle$ cat /etc/redhat-releaseRed Hat Enter ...

  6. [LeetCode] Rotate Image

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  7. C# 重绘tabControl,添加关闭按钮(页签)

    C# 重绘tabControl,添加关闭按钮(页签) 调用方法 参数: /// <summary> /// 初始化 /// </summary> /// <param n ...

  8. php计算几分钟前、几小时前等

    function format_date($time){ $t=time()-$time; $f=array( '=>'年', '=>'个月', '=>'星期', '=>'天' ...

  9. RTP 与RTCP 解释. 含同步时间戳

    转自:http://blog.csdn.net/wudebao5220150/article/details/13816225 RTP协议是real-time transport protocol的缩 ...

  10. Salesforce中所有常用类型字段的取值与赋值

    Salesforce中所有常用字段类型的定义以及如何用代码进行取值和赋值: Field Type的定义: http://www.salesforce.com/us/developer/docs/api ...