Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2016 /round2 /carnival_coins.html
wjomlex's picture
2016 Problems
07f695f verified
<p>
At the local carnival you find a midway game advertising "TONS OF FABULOUS PRIZES". Certainly a fabulous prize or two would make your
time worthwhile. It turns out that "TONS" is actually a bit of of an understatement. There are in fact <em>infinitely</em> many prizes available.
Consequently, the game operator is willing to give you a chance to score multiple prizes in a single game (for a nominal fee).
<p>
<p>
After you hand over your money, the game operator gives you <strong>N</strong> coins. Each coin has the same probability
<strong>p</strong> of landing on heads when flipped (and consequently probability 1 - <strong>p</strong> of landing on tails).
She also gives you a goal, an integer <strong>K</strong>.
</p>
<p>
As long as you still have some coins remaining, you can select any number of them and flip them all simultaneously. These coins are then
taken away. If at least <strong>K</strong> of them land on heads, you win a prize. If you play optimally, what is the expected number of
prizes you'll manage to win?
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of times you play the game.
For each attempt, there is a line containing the space-separated values <strong>N</strong>, <strong>K</strong> and
<strong>p</strong>. <strong>N</strong> and <strong>K</strong> are integers, and <strong>p</strong> is given with at most 16 decimal places.
</p>
<h3>Output</h3>
<p>
For the <strong>i</strong>th attempt, print a line containing "Case #<strong>i</strong>: " followed by the expected number of prizes
you'll win. Your output should have at most 10<sup>-6</sup> absolute or relative error.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 100 <br />
1 &le; <strong>N</strong> &le; 3,000 <br />
1 &le; <strong>K</strong> &le; 3,000 <br />
0 &le; <strong>p</strong> &le; 1 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, flipping the coins together gives you a 75% chance of winning a prize. If you flip them separately, you get a 50% chance on each flip. The latter approach is better, giving you 1 expected prize rather than 0.75 expected prizes. In the second case, it is optimal to partition the ten coins into two sets of five. In the third case, it is optimal to flip all ten coins at once.
</p>