CoinReversing
SRM 518 · 2011-05-25 · by omeometo
Problem Statement
Notes
- When you choose a specified number (say x) of coins, each combination of x coins has the same probability of being chosen.
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- N will be between 1 and 1000, inclusive.
- a will contain between 1 and 50 elements, inclusive.
- Each element in a will be between 1 and N, inclusive.
3
{2,2}
Returns: 1.6666666666666667
You first reverse 2 coins from heads to tails. Then you randomly choose 2 coins and reverse them. There are two possible situations that can occur on the second operation: Choosing 2 tails (which occurs with probability 1/3): it results in 3 heads. Choosing 1 head and 1 tail (which occurs with probability 2/3): it results in 1 head. So the expected number of heads is 1/3*3+2/3*1=5/3.
10
{10,10,10}
Returns: 0.0
You reverse every coin three times, so after the operations there will be 10 tails and no heads.
10
{2,7,1,8,2,8}
Returns: 4.792639999999999
1000
{916,153,357,729,183,848,61,672,295,936}
Returns: 498.1980774932278
50
{50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50}
Returns: 50.0
Submissions are judged against all 110 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CoinReversing with a public method double expectedHeads(int N, vector<int> a) · 110 test cases · 2 s / 256 MB per case