ScrabbleBet
SRM 293 · 2006-03-17 · by supernova
Problem Statement
You will solve a more general problem using the following parameters:
- an int trials denoting the number of meetings in which a set of games is played.
- an int games denoting the number of games that are to be played in each meeting.
- an int winsNeeded denoting the number of victories you need in one of the meetings to win the bet.
- an int winChance denoting the probability in percent of winning one particular game.
Return a double between 0 and 1, denoting the probability you have to win the bet.
Notes
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- trials will be between 1 and 50, inclusive.
- games will be between 1 and 20, inclusive.
- winsNeeded will be between 1 and games, inclusive.
- winChance will be between 0 and 100, inclusive.
2 2 1 50 Returns: 0.9375
There are 4 possible ways a meeting could evolve: - you lose both games. - you lose game 1 and you win game 2. - you win game 1 and you lose game 2. - you win both games. Your opponent has a 1/4 chance of not losing the bet after the first meeting. Since there are two meetings, your opponent's chances to win the bet are 1/4 * 1/4 = 1/16. Thus, you have a 15/16 chance to win the bet.
2 2 2 50 Returns: 0.4375
This time your opponent has a 3/4 chance of not losing the bet after one meeting and a 9/16 chance of not losing the bet after the two meetings. Your chances are now 1 - 9/16 = 7/16.
10 10 5 25 Returns: 0.5566860567603682
2 20 5 10 Returns: 0.08448495352665641
50 15 1 0 Returns: 0.0
Submissions are judged against all 108 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ScrabbleBet with a public method double estimate(int trials, int games, int winsNeeded, int winChance) · 108 test cases · 2 s / 256 MB per case