FixedDiceGameDiv2
SRM 626 · 2013-12-22 · by lg5293
Problem Statement
Alice and Bob are playing a game. Alice has an a-sided die. Bob has a b-sided die. (The faces of an n-sided die have numbers 1 through n written on them.)
The game is simple: Each player rolls their die, and the player who rolls a strictly larger number wins. (It is possible that neither player wins.)
You are given the
Notes
- Your return value must have absolute or relative error smaller than 1e-9.
- The expected value can be seen as the average of many experiments. In our case, suppose that you folow a lot of games, and each time Alice wins, you write down her score. As you watch more and more games, the average of all numbers you have written down will converge to the expected value you should return.
Constraints
- a and b will each be between 2 and 1000, inclusive.
2 2 Returns: 2.0
Alice can only win if she rolls a 2 and Bob rolls a 1. Thus, if we know Alice wins, we know she rolled a 2.
4 2 Returns: 3.2
3 3 Returns: 2.6666666666666665
11 13 Returns: 7.999999999999999
6 6 Returns: 4.666666666666667
Submissions are judged against all 58 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FixedDiceGameDiv2 with a public method double getExpectation(int a, int b) · 58 test cases · 2 s / 256 MB per case