Connection Status:
Competition Arena > FixedDiceGameDiv2
SRM 626 · 2013-12-22 · by lg5293 · Math
Class Name: FixedDiceGameDiv2
Return Type: double
Method Name: getExpectation
Arg Types: (int, int)
Problem Statement

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 ints a and b. The players already rolled their dice. You do not know what numbers they rolled, but you know that Alice won the game. Compute and return the expected value of the number Alice rolled.

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.
Examples
0)
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.

1)
4
2
Returns: 3.2
2)
3
3
Returns: 2.6666666666666665
3)
11
13
Returns: 7.999999999999999
4)
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.

Coding Area

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

Submitting as anonymous