KPGAME - A game with probability
Alice and Bob play the following game. First, they collect N small stones and put them together in one pile. After that, they throw a coin one by one. Alice starts first. If a player throws heads then he takes exactly one stone from the pile. In case of tails he don't do anything. The one who takes the last stone wins. For each player, his skill of throwing a coin is known (to everyone, including himself and his opponent). More precisely, if Alice wants to throw some specific side of the coin, she always succeeds with probability P. The same probability for Bob is Q. You are to find probability that Alice will win the game if both guys play optimally.
Input
Input starts with a line containing one integer T - a number of test cases (1 <= T <= 50). Then T test cases follow. Each of them is one line with three numbers N, P, and Q separated with a space (1 <= N <= 99999999, 0.5 <= P, Q <= 0.99999999). P and Q have not more than 8 digits after decimal point.
Output
For each test case output one line with a probability that Alice will win the game. Your answer must be precise up to 10^-6.
Example
Input: 1 1 0.5 0.5 Output: 0.666666667
hide comments
Mayank Poply:
2015-06-04 14:55:23
can anyone give some more test cases?
|
|
Efim:
2011-07-26 19:00:36
I enjoyed it. |
|
Martin:
2011-05-24 03:52:01
How to AC this problem in JAVA? I always gets "runtime error" with "(NZEC)".
|
|
~ adieus ~:
2009-08-20 03:25:57
a total maths problem. Last edit: 2009-08-20 03:27:09 |
|
Pavel Kuznetsov:
2009-03-16 19:40:26
If X is your answer and Y author's answer, then you'll get accepted only if |X-Y|<=10^-6. So, if the correct answer is 0.123 then you can just output 0.123 or 0.122999999999999999. |
|
.:: Pratik ::.:
2009-03-16 17:11:15
how many digits to print in decimal ?
|
Added by: | Pavel Kuznetsov |
Date: | 2009-03-16 |
Time limit: | 0.100s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Vologda 2009 |