|
Two chess grandmasters, Andrew and Jacob, are having an epic chess showdown to |
|
determine which of them is the uncontested best player in the world! |
|
|
|
The showdown consists of **N** games. In each game, one player plays as White |
|
and the other plays as Black. In the first game, Andrew plays as White. After |
|
each game, the player who loses it chooses which color they'll play as in the |
|
following game. However, the victor of the final game wins the entire |
|
showdown, regardless of the results of the previous games! |
|
|
|
In each game, each player may decide to attempt to win or attempt to lose: |
|
|
|
1. If both players play to win, then Andrew wins with probability **Ww** if he plays as White (and loses with probability 1 - **Ww**, as there are no draws at this high level of play). Similarly, he wins with probability **Wb** if he plays as Black. |
|
2. If both players play to lose (achieved by tipping over their own king as quickly as possible), then Andrew loses with probability **Lw** if he plays as White, and loses with probability **Lb** if he plays as Black. |
|
3. If exactly one player wants to win a game, then he's guaranteed to win it. |
|
|
|
Assuming both players play optimally in an attempt to win the showdown, what |
|
is Andrew's probability of besting Jacob? |
|
|
|
### Input |
|
|
|
Input begins with an integer **T**, the number of showdowns between Andrew and |
|
Jacob. For each showdown, there is first a line containing the integer **N**, |
|
then a line containing the space-separated values **Ww** and **Wb**, then a |
|
line containing the space-separated values **Lw** and **Lb**. These |
|
probabilities are given with at most 9 decimal places. |
|
|
|
### Output |
|
|
|
For the **i**th showdown, print a line containing "Case #**i**: " followed by |
|
the probability that Andrew wins the entire showdown. Your output should have |
|
at most 10-6 absolute or relative error. |
|
|
|
### Constraints |
|
|
|
1 ≤ **T** ≤ 10,000 |
|
1 ≤ **N** ≤ 1,000,000,000 |
|
0 ≤ **Ww**, **Wb**, **Lw**, **Lb** ≤ 1 |
|
|
|
### Explanation of Sample |
|
|
|
In the first showdown, Andrew plays White and wins the only game with |
|
probability 0.9. In the second showdown, Jacob will throw the first game to |
|
force Andrew to play Black in the second game. Jacob can guarantee a loss in |
|
the first game, and Andrew will win the second game with probability 0.8. |
|
|
|
|