File size: 2,408 Bytes
07f695f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<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 ≤ <strong>T</strong> ≤ 50 <br />
0 ≤ <strong>A</strong> < <strong>B</strong> ≤ 1,000,000,000 <br/>
1 ≤ <strong>N</strong> ≤ 100,000 <br />
1 ≤ <strong>C<sub>i</sub></strong> ≤ 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>
|