Odds of Mia
Time limit1sMemory limit1024 MB
Given partly unknown dice for both players in Mia, output player 1's winning probability as a reduced fraction, or 0 or 1 when it is certain.
- Level
Medium4 of 10
- Topics
- Probability, Brute force, Math
- Solved
- No attempts yet
Problem
This problem relates to the game of Mia introduced earlier. We recommend that you first solve Mia to understand how the game is scored. In this problem, you are asked to compute the odds that player 1 will win given partial knowledge of both rolls.
Input
The input contains multiple test cases. Each test case is one line with four symbols s0 s1 r0 r1. s0 and s1 are the dice rolled by player 1, and r0 and r1 are the dice rolled by player 2. A * means the value is not known, and a digit is the known value of the die. The input ends with a line containing four zeros.
Output
For each test case, output the odds that player 1 will win. If the odds are 0 or 1, output 0 or 1. Otherwise, output the odds as a/b, where a and b are the numerator and denominator of the fraction in lowest terms.
Hint
For * * 1 2, the best player 1 can do is tie, so the chance of winning is 0.
For 1 2 * *, player 1 wins unless player 2 rolls a Mia, which happens 1 out of 18 times.
For 1 2 1 3, 3 1 2 1, and 6 6 6 6, the result is already known.
For * 2 2 2, player 1 wins only if the roll is a 1.
For * 2 * 6, player 1 wins if the roll is a 1. If the roll is a 2, player 1 wins with probability 5/6, and loses on a 3, 4, or 5. If the roll is a 6, player 1 wins only if player 2 rolls a 1. The chance of winning is therefore .
When no dice are known, player 1 wins in 615 of the 1,296 outcomes. Player 2 loses in 615 cases, and 66 outcomes are ties. Thus, player 1's chance of winning is .