Under construction

Still being built. Things may change

Game, Set and Match

Time limit1sMemory limit128 MB

Summary
Given the per-point win probability p, compute the probabilities of winning a tennis game, set, and match using the standard scoring rules.
Level

Medium5 of 10

Topics
Dynamic programming, Probability, Math, Simulation
Solved
No attempts yet

Problem

In this problem you help compute the probability of winning at tennis. Here is a brief explanation of how the scoring system works. In a tennis match, players play a number of consecutive sets. Each set is made up of a series of games (and may include a tie-break if needed). Finally, each game is made of points.

Points. Every point is started by one player serving (that is, hitting the ball into the service box in the opposite court) and the other receiving serve. The server then attempts to return the ball into the server's court, and the players alternate hitting the ball across the net. When one of them fails to make a legal return (for example, if the ball is knocked out of the court), that player loses the point. The specifics of how points are won are not important to us.

Games. As a player wins points in a game, their score goes from the initial value of 0 (love) to 15, 30, then 40. There is no a-priori limit on the number of points in a game, but the score is always shown using these numbers, according to the following rules. When a player has three points (a score of 40) and wins the following point as well, they win the game — unless the score was 40-40 (deuce). From deuce, a player must win two points in a row to win the game: winning one point gives that player the advantage; winning the next one as well wins the game, but losing it returns the score to deuce.

Example: at 40-30, if the first player wins the next point, they win the game. If instead the second player wins the next three points, the game is theirs.

Sets. A player wins a set by winning at least six games in the set and leading by at least two games — with one exception. If the game score reaches 6-6, a tie-break is played to decide the set instead. Example: at 5-4, if the first player wins the next game they take the set 6-4; if they lose it, the set is still undecided and may end 7-5, 5-7, or in a tie-break.

Tie-break. A tie-break (and the set it belongs to) is won when a player wins at least seven points with a margin of at least two points.

Match. The winner of the match is the first player to win 2 sets (the wins need not be consecutive). A match therefore lasts 2 or 3 sets.

Rafa has studied his past performances against his next opponent and knows he wins each point with probability exactly pp, independent of whether he is serving or receiving and of all other points played. Help him assess his chance of winning the match.

Input

Each test case is a single line containing one real number pp with 0≤p≤10 \le p \le 1. The line with the value −1-1 marks the end of the input.

Output

For each test case, print one line with three numbers: the probabilities that Rafa wins a game, a set, and the match, respectively, separated by single spaces. Print each probability with exactly 8 digits after the decimal point (for example, using printf %.8f).

Examples1

  1. Example 1

    Input
    0.5
    0.3
    0.7
    -1
    
    Expected output
    0.50000000 0.50000000 0.50000000
    0.09921103 0.00016770 0.00000008
    0.90078897 0.99983230 0.99999992