God! Save me
Input: standard input
Output: standard output
Time Limit: 1 second
Let there be n doors in a mine contained room. If you choose ith door, it either takes you to a safe place after xi hours or it returns you to the same room after xi hours traveling. What is the expected length of time (in hours, let P) until you can move to the safe place?
Input The first
line in the input file is an integer representing
the number of test cases. Each of the test cases follows below. The
first line of each case
consists an integer denoting the value of n ( 0 < n < 100 ).
Each of the next n lines contains the value of xi
, 0 < |xi
|< 25
(if positive it takes you out, if negative it returns you)
and pi denoting the probability to choose the
ith door. You can assume that the sum of all pi equals 1. There may be arbitrary number of spaces
between the values. For
each test case, first print the serial number of the case, a colon, an
space and then print "God! Save me" (without the quotes)
if you can't expect to be in the safe place, else print the value of P
corrected to two digits after decimal point.
Check the sample input & output. Sample Input 3 2 0.33 -3 0.33 -5 0.34 3 2 0.34 -3 0.33 -5 0.33 Case 2: 9.76 "~~ What I
want, I find them mistakenly. I don't want what I find ~~
Output
2
Sample
Output
Case 1: 10.15Problem setter: Anupam Bhattacharjee, CSE, BUET
Thanks to Robin for the alternate solution.