#P13386. [GCJ 2011 Finals] Google Royale

    ID: 15254 远端评测题 6000~12000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2011Special Judge概率论期望Google Code Jam

[GCJ 2011 Finals] Google Royale

题目描述

While visiting the planet Theta VIII, your team of space explorers is forced to participate in the plot of a badly-written book, which takes place in a hotel/casino called the Google Royale. In order to escape the Royale, you will have to make enough money from gambling that you can buy the hotel for VV dollars and leave.

You start with AA dollars, and you will participate in betting rounds until one of two conditions is met. If you finish any betting round with 0\leq 0 dollars, you will lose; if you finish a betting round with V\geq V dollars, you will buy the hotel and leave. Otherwise you'll keep starting new betting rounds.

Each betting round consists of one or more coin flips. If you have XX dollars at the start of the round, you can choose any integer BB between 11 and min(X,M)\min(X, M) to bet on the first coin flip.

With probability 50%50\%, you win the coin flip, and the Royale immediately pays you BB dollars. You now have X+BX + B dollars, and the betting round ends.

With probability 50%50\%, you lose the coin flip and owe the Royale BB dollars. You can now pay the BB dollars you owe and end the round. Or if 2BM2B \leq M, you can instead delay the payment and do a second coin flip with twice the bet: 2B2B dollars. If you lose again, then you owe the Royale B+2B=3BB + 2B = 3B dollars. You can continue doubling your bet in this way to 4B4B, 8B8B, etc., until either you win a coin flip, you choose to stop, or your next bet would exceed MM. You can even continue if the total of all your bets in the current betting round exceeds XX.

Once the round is over, you must pay the Royale for each coin flip you lost, and if you won a coin flip, the Royale pays you for that. For example, if you start with a bet of 11 dollar, lose three coin flips, and then win one, you would gain 8421=18 - 4 - 2 - 1 = 1 dollar. If you lose three coin flips and then stopped, you would lose 4+2+1=74 + 2 + 1 = 7 dollars. If you are left with 00 or less after paying, then you are broke, and you have just lost the game.

Luckily you have brought an android with you, and he is able to compute the probability that you will win if you follow an optimal strategy. What is that probability, and what is the largest possible first bet you could make to have that probability? Remember that you are not allowed to bet more than MM!

Example

Suppose that you decide to use the following (sub-optimal) strategy. You have A=5A=5 dollars; M=20M=20 and V=40V=40. The following sequence of events is possible:

  • Round 1: You can start by betting 11, 22, 33, 44 or 55 dollars. You decide to begin a betting round by betting 22 dollars.
    • Step 1 (B=2B=2): You win the first coin flip. You gain 22 dollars, and the betting round ends. Now you have 77 dollars.
  • Round 2: You begin a betting round by betting 55 dollars.
    • Step 1 (B=5B=5): You lose the first coin flip. Now you owe the Royale 55 dollars. Since 5×2205\times 2 \leq 20, you may do another coin flip with a bet of 5×2=105\times 2=10 dollars. You choose not to. You lose 55 dollars, and the betting round ends. Now you have 22 dollars.
  • Round 3: You begin a betting round by betting 22 dollars.
    • Step 1 (B=2B=2): You lose. Now you owe the Royale 22 dollars. You choose to flip another coin with a bet of 44 dollars.
    • Step 2 (B=4B=4): You lose. Now you owe the Royale a total of 66 dollars. That's more than you have, which is okay. You choose to flip another coin with a bet of 88 dollars.
    • Step 3 (B=8B=8): You win. You gain 88 dollars, pay the 2+4=62+4=6 dollars you owe, and the betting round ends. Now you have 44 dollars.
  • Round 4: You begin a betting round by betting 22 dollars.
    • Step 1 (B=2B=2): You lose. Now you owe the Royale 22 dollars. You choose to flip another coin with a bet of 44 dollars.
    • Step 2 (B=4B=4): You lose. Now you owe the Royale a total of 66 dollars. You choose to flip another coin with a bet of 88 dollars.
    • Step 3 (B=8B=8): You lose. Now you owe the Royale a total of 1414 dollars. You choose to flip another coin with a bet of 1616 dollars.
    • Step 4 (B=16B=16): You lose. Now you owe the Royale a total of 3030 dollars. Since 2×16>M2\times 16>M, you cannot flip another coin and you must pay what you owe. Now you have 26-26 dollars; you have lost.

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each line contains three integers separated by single spaces: AA, MM and VV, in that order.

输出格式

For each test case, output one line containing "Case #xx: yy zz", where xx is the case number (starting from 11); yy is the probability of winning if you follow an optimal strategy; and zz is the maximum first bet you can make without reducing your probability of winning. yy must be correct to within an absolute or relative error of 10610^{-6}.

4
1 1 3
3 6 12
4 20 15
13 6 20
Case #1: 0.333333333 1
Case #2: 0.500000000 3
Case #3: 0.755555555 3
Case #4: 0.730769231 6

提示

Limits

  • 1T1001 \leq T \leq 100.

Small dataset (20 Pts, Test set 1 - Visible)

  • 1M201 \leq M \leq 20.
  • 1A<V201 \leq A < V \leq 20.
  • Time limit: 30 6 seconds.

Large dataset (40 Pts, Test set 2 - Hidden)

  • 1M10161 \leq M \leq 10^{16}.
  • 1A<V10161 \leq A < V \leq 10^{16}.
  • Time limit: 60 12 seconds.