|
<p>You may be familiar with the works of Alfred, Lord Tennyson, the famous |
|
English poet. In this problem we will concern ourselves with Tennison, |
|
the less famous English tennis player. As you know, tennis is not so much |
|
a game of skill as a game of luck and weather patterns. The goal of tennis is |
|
to win <strong>K</strong> sets before the other player. However, the chance of winning a set is |
|
largely dependent on whether or not there is weather. |
|
</p> |
|
|
|
<p>Tennison plays best when it's sunny, but sometimes, of course, it rains. |
|
Tennison wins a set with probability <strong>p<sub>s</sub></strong> when it's sunny, and with probability |
|
<strong>p<sub>r</sub></strong> when it's raining. The chance that there will be sun for the first set is |
|
<strong>p<sub>i</sub></strong>. Luckily for Tennison, whenever he wins a set, the probability that there |
|
will be sun increases by <strong>p<sub>u</sub></strong> with probability <strong>p<sub>w</sub></strong>. Unfortunately, when Tennison |
|
loses a set, the probability of sun decreases by <strong>p<sub>d</sub></strong> with probability <strong>p<sub>l</sub></strong>. |
|
What is the chance that Tennison will be successful in his match?</p> |
|
|
|
<p>Rain and sun are the only weather conditions, so P(rain) = 1 - P(sun) at all |
|
times. Also, probabilities always stay in the range [0, 1]. If P(sun) would |
|
ever be less than 0, it is instead 0. If it would ever be greater than 1, it |
|
is instead 1.</p> |
|
|
|
|
|
<h2>Input</h2> |
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of tennis matches |
|
that Tennison plays. For each match, there is a line containing an integer |
|
<strong>K</strong>, followed by the |
|
probabilities <strong>p<sub>s</sub>, p<sub>r</sub>, p<sub>i</sub>, p<sub>u</sub>, p<sub>w</sub>, p<sub>d</sub>, p<sub>l</sub></strong> in that order. All of these |
|
values are given with exactly three places after the decimal point. |
|
|
|
|
|
<h2>Output</h2> |
|
<p> |
|
For each match, output "Case #i: " followed by the probability that Tennison wins the match, rounded to 6 decimal places |
|
(quotes for clarity only). It is guaranteed that the output is unaffected by deviations as large as 10<sup>-8</sup>. |
|
</p> |
|
|
|
<h2>Constraints</h2> |
|
<ul> |
|
<li>1 ≤ <strong>T</strong> ≤ 100</li> |
|
<li>1 ≤ <strong>K</strong> ≤ 100</li> |
|
<li>0 ≤ <strong>p<sub>s</sub>, p<sub>r</sub>, p<sub>i</sub>, p<sub>u</sub>, p<sub>w</sub>, p<sub>d</sub>, p<sub>l</sub></strong> ≤ 1</li> |
|
<li><strong>p<sub>s</sub></strong> > <strong>p<sub>r</sub></strong></li> |
|
</ul> |
|
|