106 miles to Chicago 2010.3.6

来源:互联网 发布:文豪野犬 知乎 编辑:程序博客网 时间:2024/05/18 13:28

106 miles to Chicago 2010.3.6

 

Time Limit:2000MS  Memory Limit:65536K

Total Submit:51 Accepted:14

 

Description

 

In the movie "Blues Brothers",the orphanage where Elwood and Jack were raised may be sold to the Board ofEducation if they do not pay 5000 dollars in taxes at the Cook CountryAssessor’s Office in Chicago.After playing a gig in the Palace Hotel ballroom to earn these 5000 dollars,they have to finda 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 andthey are wearing sunglasses. As they are on a mission from God, you should helpthem find the safest way to Chicago.In this problem, the safest way is considered to be the route which maximisesthe probability that they are not caught.

 

Input

 

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 ofstreets to be considered. The next m lines contain the description of thestreets. 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 endpoints of the street and p is the probability in percent that the BluesBrothers will manage to use this street without being caught. Each street canbe used in both directions. You may assume that there is at most one streetbetween two end points. The last test case is followed by a zero.

 

Output

 

For each test case, calculate theprobability of the safest path from intersection 1 (the Palace Hotel) tointersection n (the Honorable Richard J. Daley Plaza in Chicago). You can assume that there is atleast one path between intersection 1 and n. Print the probability as apercentage with exactly 6 digits after the decimal point. The percentage valueis 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

 

Source

 

ULM 2005


#include <stdio.h>#include <string.h>#define MAXN 100+10double f[MAXN][MAXN];int n,m,i,j,k;void main(){int a,b,c;double temp;while (scanf("%d",&n),n!=0){scanf("%d",&m);memset(f,0,sizeof(f));for(i=1;i<=m;i++){scanf("%d %d %d",&a,&b,&c);f[a][b]=(double)c/100.0;f[b][a]=f[a][b];}for(k=1;k<=n;k++)for(i=1;i<=n;i++)if (k!=i)for(j=1;j<=n;j++)if ((i!=j)&&(k!=j))if ((f[i][k]!=0)&&(f[k][j]!=0)){temp=f[i][k]*f[k][j];if (temp>f[i][j])f[i][j]=temp;}printf("%.6lf percent\n",f[1][n]*100);}}


0 0
原创粉丝点击