TheDiceGame
SRM 381 · 2007-12-08 · by Vasyl[alphacom]
Problem Statement
Little John has one standard die with numbers one to six on its sides. Each time he throws the die, he gets as many candies from his mom as the number on the top of the die. Johnâs goal is to collect at least candies candies. Then he will eat them all and became a little fat boy.
Return the expected number of throws needed for John to achieve his goal.
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- candies will be between 1 and 1000000, inclusive.
1 Returns: 1.0
John needs only one throw to get at least one candy.
2 Returns: 1.1666666666666667
After the first throw, there is a probability of 1/6 that John will need an additional throw.
7 Returns: 2.5216263717421126
47 Returns: 13.90476189046144
9 Returns: 3.0433247837600974
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 TheDiceGame with a public method double expectedThrows(int candies) · 80 test cases · 2 s / 256 MB per case