Problem Statement
Alice and Bob are playing a game. Alice rolls a identical b-sided dice. Bob rolls c identical d-sided dice. The sides of an n-sided die have numbers 1 through n written on them.
A player's score is the sum of the numbers they rolled on their dice. The player with a strictly higher score wins. It is possible that neither player wins.
You are given the ints a, b, c, and d. The players already rolled their dice. If it's not possible for Alice to win, return -1. Otherwise, assume that you don't know what numbers Alice and Bob rolled, but that you know that Alice won the game. Return the expected value of Alice's score (given the above assumption).
Definition
- Class:
- FixedDiceGameDiv1
- Method:
- getExpectation
- Parameters:
- int, int, int, int
- Returns:
- double
- Method signature:
- double getExpectation(int a, int b, int c, int d)
- (be sure your method is public)
Notes
- Your return value must have an absolute or relative error smaller than 1e-3.
Constraints
- a, b, c, d will each be between 1 and 50, inclusive.
Examples
1
2
1
5
Returns: 2.0
The only way Alice can win is if she rolls a 2. Thus, if we know Alice wins, we know she rolled a 2.3
1
1
3
Returns: 3.0
Alice will always roll a 3.1
5
1
1
Returns: 3.4999999999999996
Alice will not win if she rolls a 1. Thus, if we know she wins, her expected score is (2+3+4+5)/4=7/2.2
6
50
30
Returns: -1.0
No matter what Alice rolls, she will lose.50
11
50
50
Returns: 369.8865999182022