This page is still under construction.

Parts of this page are still being built. What you see may change.

Wimbledon

Time limit1sMemory limit128 MB

Summary
Compute the expected match length in minutes from each player's chance of winning a game on serve under best-of-five tennis scoring.
Level

Medium6 of 10

Topics
Probability, Dynamic programming
Solved
No attempts yet

Problem

The trip is over and it is time to fly home. I have plenty to regret, but the worst part is that the Wimbledon match will finish while I am 20,000 feet in the air.

Wait, I had that wrong. The match starts in the afternoon, and tennis can run as long as it wants. If it lasts into the evening I might get to watch it after all. So when does a match end?

For every player I know the probability that the player wins a game on his own serve. A match is split into sets, a set is split into games, and the odds change depending on who serves, so I cannot work out the length by myself.

The rules are simple.

  • A match between two players is played over several sets. The moment one player wins his third set the match stops, so the final set score is 3-0, 3-1, or 3-2.
  • A set is played over several games, and one game always takes 5 minutes.
  • A set ends as soon as one player has won at least 6 games and leads the opponent by at least 2 games. That player wins the set.
  • If the game score reaches 6-6, one more tie break game is played and its winner takes the set.
  • So the game score of a set has only seven possible values: 6-0, 6-1, 6-2, 6-3, 6-4, 7-5, and 7-6 decided by the tie break.
  • One player serves a whole game, and the serve passes to the opponent every time a game ends. It alternates no matter who won the game, and the alternation carries across set boundaries through the entire match. The tie break game follows the same serving order and also takes 5 minutes.

For example, say A serves first in a match against B and some set ends 6-1. A served the last game of that set, so B serves first in the next set. It does not matter which player won the set. The opponent of the player who served the last game of the previous set serves the first game of the next set.

All I know is the probability that the serving player wins a game. Write a program that computes the expected time until a match between two players ends.

Input

The first line has the number of test cases T.

Each test case is two lines. The first line has the surname and the given name of the player who serves first, separated by a space, followed by the probability that this player wins a game on his own serve, given as an integer percentage. The second line has the surname and the given name of his opponent, followed by that player's probability in the same format.

Both probabilities are integers between 0 and 100. Surnames and given names contain no spaces.

Output

For each test case print one line in the form Case #x: y. Here x is the test case number starting from 1, and y is the expected time in minutes until that match ends.

Round y at the seventh digit after the decimal point, print six digits after the decimal point, and pad with zeros so that there are always six digits. The inputs are built so that no answer lands on a rounding boundary.

Hint

If one player wins every game, all three sets end 6-0 and the match is over after 18 games. That match always takes 90 minutes.

Examples1

  1. Example 1

    Input
    2
    Rafael Nadal 50
    Roger Federer 50
    Pete Sampras 100
    Hamza Darwish 0
    
    Expected output
    Case #1: 199.281006
    Case #2: 90.000000