TopCoder problem "TheDiceGame" used in SRM 381 (Division I Level One , Division II Level Two)



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.

 

Definition

    
Class:TheDiceGame
Method:expectedThrows
Parameters:int
Returns:double
Method signature:double expectedThrows(int candies)
(be sure your method is public)
    
 

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.
 

Examples

0)
    
1
Returns: 1.0
John needs only one throw to get at least one candy.
1)
    
2
Returns: 1.1666666666666667
After the first throw, there is a probability of 1/6 that John will need an additional throw.
2)
    
7
Returns: 2.5216263717421126
3)
    
47
Returns: 13.90476189046144

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8414

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10804&pm=8414

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , Olexiy , ivan_metelsky , ged

Problem categories:

Simple Math