Canadian Computing Olympiad: 2015 Day 2, Problem 3
It's time for a vacation! You are sick and tired of C shells, so you decide to become a seashell collector.
For your vacation, you have decided to visit the beautiful island nation of Cartesia. It is well-known for having a lovely square beach that is composed of an
There are
Complicating matters is a glorious dodo bird running around the beach. At a given moment, it may decide to bury an egg in a grid cell (including grid cells that have eggs or shells already). The bad news is that if the
After all is said and done, you decide to sit back, go back to programming, and simulate the digging instead. You will be computing the probability that your scoop, when chosen uniformly from all valid possible scoops, will make at least a given minimum profit (to pay off your student loans) at different points in time. Who wants to get all sweaty from shoveling on a beach anyway?
Input Specification
The first line of input contains two integers
The second line of input contains the integer
The next line contains
1
( ), meaning that the dodo just buried an egg in the grid cell ;2
( ), meaning we would like to calculate the probability that a random dig at this point in time has profit in dollars . Note that no shells or eggs are actually removed or added when this probability is calculated.
For at least 15% of the marks for this question,
For an additional 25% of the marks for this question, all update operations will occur before all query operations.
Output Specification
For each query operation, output on one line the probability that a random scoop would contain at least the desired number of different types of shells.
Your answer must be within
Sample Input
4 2
3
3 1 1 2 3 4 2
3 1 4 2 3 3 2
4 2 1 2 4 4 1 4 4
6
2 2
2 3
1 2 3
2 2
2 3
2 4
Output for Sample Input
0.88889
0.33333
0.44444
0.11111
0.00000
Explanation for Sample Output
Initially, we have the following arrangement of shells (with the first shells in the input being labelled as 1, and so on):
1 | 2 | ||
3 | 1, 2 | 3 | |
2 | |||
3 | 1 | 3 |
and our shovel will scoop up a
With no eggs present, 8 of the 9 scoops contain at least two species of shells and 3 of the 9 scoops contain three species of shells.
An egg is then dropped into the cell that contains 1, 2
.
Then, 4 of the 9 scoops contain at least two species of shells and no eggs and only 1 scoop (the bottom-leftmost scoop) would contain all three species of shells and no eggs. The final output indicates there are no scoops which contain 4 different species of shells.
Comments
It seems the judge only checks 5 decimal places.