D |
Table
Tennis |
|
Table tennis is a two/four player sport
that originated in England. The scoring system of this game has changed with
time. For this problem we will consider the two-player version of the game that
abides by the following scoring rules (note that this rule is significantly
different from the usual ones) –
·
Player 1 makes the first move. The players
alternate serve every 5 points. That means serves [1,5]
are done by player 1, serves [6, 10] are done by player 2, serves [11, 15] are
done by player 1 and so on.
·
In each serve, one of the two players
wins a point. The first player to reach 21 points wins the game.
·
If the scores are 20-20 (deuce), the
scores are reset to 15-15.
Given
a partial game, the probability of player 1 winning a point on his serve and
the probability of player 1 winning a point on the opponent’s serve, can you
find out the probability of player 1 winning the game?
Input
The
first line of input is an integer T(T<1000) that
indicates the number of test cases. Each case consists of two lines. The first
line is a string consisting of the letters “W” and “L” only. The length of this
string is non-negative and can have a maximum value of 100. The string gives
the status of the game so far. If the ith
character (1 based) is “W”, that means player 1 won the ith
point. Similarly, “L” indicates that the player 1 lost that point. The next
line consists of two real numbers, P1 P2, in the range [0, 1], with at
most 3 digits after the decimal point. P1 is the probability of player 1
winning a point on his serve and P2 is the probability of player 1 winning a
point on player 2’s serve.
Output
For each case, output the case number first. Then output the
probability of player 1 winning the game rounded to 6 decimal places. If the given partial game is impossible according to any of the
rules or data, output "-1.000000" instead. Outputs will be checked
with special judge, so small precision errors will be ignored. Look at the
samples for exact format.
Sample
Input |
Sample
Output |
4 WWWWWWWWWWWWWWWWWWWW 1.0
0.234 WWWWWWWWWWWWWWWWWWWWW 0.3
0.99 WWWWWWWWWWWWWWWWWWWWWW 1.0
1.0 WL 0.7
0.3 |
Case
1: 1.000000 Case
2: 1.000000 Case
3: -1.000000 Case
4: 0.444026 |
Problem Setter: Sohel Hafiz, Special
Thanks: Samee Zahur
Illustration
Case 1: Player 1 has already won 20 points and next it’s his
serve. To win the next point (which is also the game point) he has a 1.0
probability of winning
Case 2: Player 1 has already won 21
points and he won the game and so it’s 1.000000.
Case 3: The game should stop after 21
points, but the string has an extra “W” and makes this game invalid, so output
is -1.000000.