TheTicketsDivTwo
SRM 504.5 · 2011-04-28 · by Vasyl[alphacom]
Problem Statement
While the initial John's intention is to throw a die until some friend is chosen, in practice he gets tired quickly. If after k throws of a die he still hasn't chosen a friend, he prefers to stop the process and to choose the friend who is currently first in line.
You are given an
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- n will be between 1 and 10, inclusive.
- m will be between 1 and n, inclusive.
- k will be between 1 and 10, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
2 1 1 Returns: 0.16666666666666666
There is 1/6 probability that John will choose the first friend after the first throw of a die.
2 1 2 Returns: 0.5833333333333334
The first friend will go to the game if John chooses him after the first throw, or if he goes to the end of the line after the first throw and Jonh doesn't choose the second friend after the second throw. The overall probability is 1/6 + 1/2 * 5/6.
7 7 4 Returns: 0.0
There's no chance for the last friend in the line to be chosen.
4 2 10 Returns: 0.25264033564814814
9 1 4 Returns: 0.16666666666666666
Submissions are judged against all 65 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TheTicketsDivTwo with a public method double find(int n, int m, int k) · 65 test cases · 2 s / 256 MB per case