Find the safest road--hdu1596

Source: Internet
Author: User

Find the safest road

Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9224 Accepted Submission (s): 3264


Problem Descriptionxx Planet There are many cities, each city has one or more flight lanes, but not all roads are very safe, each road has a safety factor s,s is the real number between 0 and 1 (including 0, 1), a channel p from u to V The safety is safe (P) = S (E1) *s (E2) ... *s (EK) E1,e2,ek is on the side of P, now 8600 want to go out to travel, faced with so many roads, he wanted to find the safest way. But 8600 of the math is not good, I would like to ask you to help ^_^

Input inputs include multiple test instances, each of which includes:
First line: N. n indicates the number of cities n<=1000;
Then there is a n*n matrix that represents the safety factor between the two cities (0 can be understood as there is no direct channel between the two cities)
followed by the Q 8600 route to travel, each line has two numbers, indicating the city of 8600 and the city to go

Output If 86 fails to reach his destination, outputs "What a pity!",
The other outputs the safety factor of the safest road between these two cities and retains three decimal places.

Sample Input31 0.5 0.50.5 1 0.40.5 0.4 131 22 31 3

Sample Output0.5000.4000.500

The idea is to calculate that the safe value of the road is multiplied rather than added!

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Doublemap[1010][1010],flag;6 Doubled[1010];7 intN;8 voidDijkstraintXinty)9 {Ten     inti,j,used[1010],mark; One     DoubleMax; A      for(i=1; i<=n;i++) -     { -used[i]=0; thed[i]=Map[x][i]; -     } -     d[x]=0; -     used[x]=1; +      -      for(i=1; i<=n;i++) +     { Amax=-1; mark=-1; at              for(j=1; j<=n;j++) -             { -                 if(!used[j]&&d[j]>max)//Find the largest -                 { -max=D[j]; -mark=J; in                 } -             } to         if(mark==-1) +          Break; -used[mark]=1; the          for(j=1; j<=n;j++) *         { $             if(d[j]<d[mark]*map[mark][j]&&!used[j])//slack OperationPanax Notoginsengd[j]=d[mark]*Map[mark][j]; -         } the     } + if(D[y])//If there is a road of 0, it is certainly the smallest, the safety value of this whole road is 0 Aprintf"%.3lf\n", D[y]); the Else +printf"What a pity!\n");  - } $ intMain () $ { -     inti,j; -      while(SCANF ("%d", &n)! =EOF) the     { -          for(i=1; i<=n;i++)Wuyi         { the              for(j=1; j<=n;j++) -             { Wuscanf"%LF",&map[i][j]); -             } About         } $         intm,a,b;  -scanf"%d",&m); -          for(i=0; i<m;i++) -         { Ascanf"%d%d",&a,&b); +flag=0; the Dijkstra (A, b); -         } $     }     the return 0; the}

Find the safest road--hdu1596

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.