Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2015 /finals /fox_focks.html
wjomlex's picture
2015 Problems
761e24d verified
raw
history blame
3.07 kB
<p>
Mr. Fox has opened up a fabulous Fock farm! A Fock is a cute little animal which can have either red, green, or blue fur
(these 3 possible colors can be numbered 1, 2, and 3, respectively). Furthermore, a Fock's fur color can change every second!
</p>
<p>
Mr. Fox owns a flock of <strong>N</strong> Focks, with the <strong>i</strong>th one initially having a color of <strong>C<sub>i</sub></strong>.
Every second, if the <strong>i</strong>th Fock currently has a color of <strong>a</strong>, it will switch to having a color of <strong>b</strong>
for the next second with probability <strong>P<sub>i,a,b</sub></strong>%. All Focks change color simultaneously.
</p>
<p>
After a very large amount of time has gone by, Mr. Fox will take a single photo of all of his Focks to help advertise his farm.
In particular, he picks an integer <strong>t</strong> at uniform random from the range [10<sup>100</sup>, 10<sup>1000</sup>] and waits that many seconds.
He's hoping that the photo will make it look like his farm has a well-balanced mix of Fock colors &mdash; it'll be no good if the photo ends up
featuring a strict majority of a single color (that is, strictly more than <strong>N</strong>/2 of the Focks having the same color).
What's the probability of this occurring?
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 20<br />
1 &le; <strong>N</strong> &le; 50,000<br />
1 &le; <strong>C<sub>i</sub></strong> &le; 3 for all <strong>i</strong><br />
0 &le; <strong>P<sub>i,a,b</sub></strong> &le; 100
for all <strong>i</strong>, <strong>a</strong> and <strong>b</strong><br />
<strong>P<sub>i,a,1</sub></strong> + <strong>P<sub>i,a,2</sub></strong> + <strong>P<sub>i,a,3</sub></strong> = 100
for all <strong>i</strong> and <strong>a</strong><br />
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of Fock farms Mr. Fox has.
For each farm, there is first a line containing the integer <strong>N</strong>.
Then, for each Fock <strong>i</strong>, 4 lines follow.
The first of these lines contains the integer <strong>C<sub>i</sub></strong>.
The next three lines contain three space-separated integers each, with the <strong>b</strong>th integer on the <strong>a</strong>th line being
<strong>P<sub>i,a,b</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <strong>i</strong>th farm, print a line containing "Case #<strong>i</strong>: " followed by
the probability that the <strong>i</strong>th picture contains a strict majority of some color of Fock, rounded to 6 decimal places.
</p>
<p>
Absolute errors of up to 2e-6 will be ignored.
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, the first Fock never changes color, so it'll still have color 1 in the photo.
The second Fock is likely to have color 2 for a while, but by the time the photo is taken, it'll certainly have color 3.
The third Fock will have either color 2 or 3 in the photo, with equal probability. Therefore, the photo will have a 50% chance of having a strict majority of color 3, and a 50% chance of no strict majority.
</p>