WIMB - The Grandslam of Grandslams!

no tags 

My boss hates me. He hates me to the extent where he plans meetings which clash with a Wimbledon match, almost all the time. Now, to give myself some inner peace, I decided to play well - while also trying to at least pray, that the matches I want to watch stretch enough for me to watch when I get back home.

But hey, wait! I may have a shot here! At Wimbledon, matches are played only at day light, so maybe if players were not ready to give up easily on each point, then the match will extend until sunset - just for my convenience!

So what I need to know is how long on average a game between two players will last, and to help me feel better you should write a computer program to determine that!

The result of a tennis match is determined by the number of “sets” each player wins, the first player to win three sets wins the match. Accordingly, all possible match results are 3-0, 3-1 and 3-2. The result of each set is determined by the number of “games” in the set each player wins, the first player to win six or more games with two or more game difference from the opponent wins the set, however if the result of a set (including the last set) leveled at 6-6 then a tie-break game is played to determine the set winner, Accordingly all possible set results are 6-0, 6-1, 6-2, 6-3, 6-4, 7-5 and 7-6 using a tie breaker game!

During each game (including tie-break), one player has the serve, this means that this player must start the play for all points of the game by hitting the ball, serving the ball is considered a big advantage. Assume that the serve starts at the first player and then alternates after each game till the end. Given the probability of winning a game on serve for each player against his opponent, and assuming that each game lasts for five minutes, calculate the expected duration of the match.

Input:

The first line of input contains an integer T, the number of test cases. The first line of each test case contains the first and last names of the first player, followed by an integer (0 <= A <= 100) where A/100 is the probability that the first player wins a game on his serve against the second player. The second line contains the first and last names of the second player, followed by an integer (0 <= B <= 100) where B/100 is the probability that the second player wins a game on his serve against the first player.

Output:

For each test case, print the duration of the match in minutes rounded to six decimal digits.

Sample

Input:
2
Pete Sampras 50
Rafael Nadal 50
Roger Federer 100
Arjit Srivastava 0

Output:
199.281006
90.000000

How?

In the second test case, I don’t stand a chance against Pete! He always wins all games on his serve (probability 100/100) and he also always wins all games on my serve (as I win with probability 0/100), so he always wins the match with three straight sets (6-0, 6-0, 6-0), a total of 18 games played, each lasting five minutes for a total of 90 minutes match.


hide comments
[Rampage] Blue.Mary: 2016-02-18 06:06:11

The test case of this problem is weaker than my problem TENNIS.

Mitch Schwartz: 2013-02-25 00:59:13

@Rishi: Expected value need not be an attainable value, e.g. choosing 4 or 8 with equal probability, the expected value is 6.

Rishi Poddar: 2013-02-24 16:41:09

The statement says "assuming that each game lasts for five minutes", then how can the "expected duration of the match" be anything other than a multiple of 5mins?(1st test case). Do you mean to say that a game can end in middle?

Last edit: 2013-02-24 16:54:17
LeppyR64: 2013-02-23 06:24:59

"You seem to be missing some details :)"
"Yes, you are right. Some details were lost while uploading the problem."

EDIT: The details have been put, and have been fixed. This problem is good enough, to be solved. Take your shot. :)

Last edit: 2013-02-19 16:43:45

Added by:Arjit Srivastava
Date:2013-02-19
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:LCPC