#P13386. [GCJ 2011 Finals] Google Royale
[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 dollars and leave.
You start with dollars, and you will participate in betting rounds until one of two conditions is met. If you finish any betting round with dollars, you will lose; if you finish a betting round with 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 dollars at the start of the round, you can choose any integer between and to bet on the first coin flip.
With probability , you win the coin flip, and the Royale immediately pays you dollars. You now have dollars, and the betting round ends.
With probability , you lose the coin flip and owe the Royale dollars. You can now pay the dollars you owe and end the round. Or if , you can instead delay the payment and do a second coin flip with twice the bet: dollars. If you lose again, then you owe the Royale dollars. You can continue doubling your bet in this way to , , etc., until either you win a coin flip, you choose to stop, or your next bet would exceed . You can even continue if the total of all your bets in the current betting round exceeds .
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 dollar, lose three coin flips, and then win one, you would gain dollar. If you lose three coin flips and then stopped, you would lose dollars. If you are left with 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 !
Example
Suppose that you decide to use the following (sub-optimal) strategy. You have dollars; and . The following sequence of events is possible:
- Round 1: You can start by betting , , , or dollars. You decide to begin a betting round by betting dollars.
- Step 1 (): You win the first coin flip. You gain dollars, and the betting round ends. Now you have dollars.
- Round 2: You begin a betting round by betting dollars.
- Step 1 (): You lose the first coin flip. Now you owe the Royale dollars. Since , you may do another coin flip with a bet of dollars. You choose not to. You lose dollars, and the betting round ends. Now you have dollars.
- Round 3: You begin a betting round by betting dollars.
- Step 1 (): You lose. Now you owe the Royale dollars. You choose to flip another coin with a bet of dollars.
- Step 2 (): You lose. Now you owe the Royale a total of dollars. That's more than you have, which is okay. You choose to flip another coin with a bet of dollars.
- Step 3 (): You win. You gain dollars, pay the dollars you owe, and the betting round ends. Now you have dollars.
- Round 4: You begin a betting round by betting dollars.
- Step 1 (): You lose. Now you owe the Royale dollars. You choose to flip another coin with a bet of dollars.
- Step 2 (): You lose. Now you owe the Royale a total of dollars. You choose to flip another coin with a bet of dollars.
- Step 3 (): You lose. Now you owe the Royale a total of dollars. You choose to flip another coin with a bet of dollars.
- Step 4 (): You lose. Now you owe the Royale a total of dollars. Since , you cannot flip another coin and you must pay what you owe. Now you have dollars; you have lost.
输入格式
The first line of the input gives the number of test cases, . lines follow. Each line contains three integers separated by single spaces: , and , in that order.
输出格式
For each test case, output one line containing "Case #: ", where is the case number (starting from ); is the probability of winning if you follow an optimal strategy; and is the maximum first bet you can make without reducing your probability of winning. must be correct to within an absolute or relative error of .
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
- .
Small dataset (20 Pts, Test set 1 - Visible)
- .
- .
- Time limit:
306 seconds.
Large dataset (40 Pts, Test set 2 - Hidden)
- .
- .
- Time limit:
6012 seconds.