RedPaint
TCO14 Round 1C · 2014-03-26 · by misof
Problem Statement
We have an infinite strip of paper divided into a sequence of cells. All of the cells are initially white. We place a robot onto one of the cells. Each time the robot stands on a cell, it paints the cell red.
You are given an
Compute and return the expected number of red cells at the end.
Notes
- Your return value must have an absolute or a relative error at most 10^(-9).
Constraints
- N will be between 0 and 500, inclusive.
0 Returns: 1.0
No movement. At the end there is a single red cell: the one with the robot.
1 Returns: 2.0
One step. The robot will choose a random direction and move. There will be exactly two red cells: the one where it started and the one where it ended.
2 Returns: 2.5
In the third step the robot will color a third cell red with probability 1/2. Hence, the expected number of red cells is 0.5*2 + 0.5*3 = 2.5.
4 Returns: 3.375
3 Returns: 3.0
Submissions are judged against all 80 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RedPaint with a public method double expectedCells(int N) · 80 test cases · 2 s / 256 MB per case