hackercup / 2016 /round1 /yachtzee.html
wjomlex's picture
2016 Problems
07f695f verified
raw
history blame
No virus
2.41 kB
<p>
A rich, retired programmer has decided to invest his (possibly) massive savings into constructing custom yachts for himself.
</p>
<p>
Initially, he has a real amount of dollars, chosen uniformly at random from the range [<strong>A</strong>, <strong>B</strong>].
Constructing a yacht consists of <strong>N</strong> sequential steps, with the <strong>i</strong>th step requiring <strong>C<sub>i</sub></strong> dollars.
</p>
<p>
The programmer blindly pays for the steps in order, until he's either completed all of them, or can't afford the cost of the next step.
If the former occurs, he puts his completed yacht aside and restarts the process from the first step with his remaining money - he wants as many yachts as possible!
Otherwise, in the latter case, he immediately stops his project entirely, without spending any additional money on other steps.
</p>
<p>
What's the expected amount of money which the programmer will be left with once he stops spending it on yachts? Your output should have at most 10<sup>-6</sup> absolute or relative error.
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of times the programmer embarks on a yacht-creation spree.
For each spree, there is first a line containing the space-separated integers
<strong>N</strong>, <strong>A</strong>, and <strong>B</strong> in that order,
then a line containing <strong>N</strong>
space-separated integers, the <strong>i</strong>th of which is <strong>C<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <strong>i</strong>th spree, print a line containing "Case #<strong>i</strong>: " followed by
the expected amount of money the programmer will have left.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 50 <br />
0 &le; <strong>A</strong> &lt; <strong>B</strong> &le; 1,000,000,000 <br/>
1 &le; <strong>N</strong> &le; 100,000 <br />
1 &le; <strong>C<sub>i</sub></strong> &le; 1,000,000,000 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, the programmer starts with between 5 and 8 dollars. The programmer's initial amount of money will fall into one of the ranges [5, 6), or [6, 8), or [8, 8].
If it falls into the first range, the programmer will end with [1, 2) dollars. If it falls into the second range, the programmer will end with [0, 2) dollars. If the programmer
starts with exactly 8 dollars, he'll end with 0 dollars.
</p>