#P8580. Penalty Shootout Game Expectation
Penalty Shootout Game Expectation
Penalty Shootout Game Expectation
There are (n) people playing a penalty shootout game with the following rules:
- The players are numbered \(1,2,\dots,n\). Initially, player \(1\) takes the shot, and thereafter the next shot is taken by the next player in sequence who has not been eliminated. In particular, after player \(n\) the sequence continues with player \(1\).
- If the shooter does not even touch the board, they are immediately eliminated.
- If the shooter touches the board but fails to score, then they are eliminated if and only if the immediately preceding shooter scored (except for the very first shooter, who is never eliminated on a board-touch failure).
- The game ends when only one player remains.
For each player \(i\), the probability of not touching the board is \(\frac{a_i}{1000}\), and the probability of touching the board but missing is \(\frac{b_i}{1000}\). The remaining probability \(1-\frac{a_i+b_i}{1000}\) is that of scoring. Calculate the expected total number of shots taken when the game ends.
inputFormat
The first line contains an integer \(n\) (number of players). Each of the next \(n\) lines contains two integers \(a_i\) and \(b_i\) (with \(0 \leq a_i, b_i \leq 1000\) and \(a_i+b_i \leq 1000\)), representing the probabilities as described above.
outputFormat
Output the expected total number of shots taken. Answers within an absolute or relative error of \(10^{-6}\) will be accepted.
sample
2
100 200
300 400
2.696531
</p>