Hide

Problem H
Gunslingers

There are $n$ gunslingers named $G_1, G_2, \ldots , G_ n$ in an $n$-way duel. Only one can make it out. The rules of the duel are as follows:

  1. The gunslingers stand in a circle in the order $G_1, G_2, \ldots , G_ n$ and take turns shooting in a cycle. ($G_1$ shoots if not eliminated, then $G_2$ shoots if not eliminated, and so on until $G_ n$, skipping over eliminated gunslingers. Then the cycle repeats.)

  2. Each gunslinger $G_ i$ has a non-zero chance $h_ i$ to hit their target. On each gunslinger’s turn, they must aim and shoot at one other surviving gunslinger. If they hit, the target is eliminated. If they miss, nothing happens.

    (Gunslingers cannot intentionally miss and must aim at another gunslinger. They cannot shoot themselves.)

  3. After the shot, the turn goes to the next surviving gunslinger in the cycle.

  4. The duel ends when there is exactly one gunslinger remaining. That gunslinger wins.

Each gunslinger wants to win, so they will aim at whichever target gives them the greatest chance of winning. Such a target is considered an optimal target.

If a gunslinger misses, other gunslingers cannot identify who the target was. Therefore, when calculating an optimal target, a gunslinger does not care about what happens if they miss. (This is because if a gunslinger misses, the choice of target cannot influence any other gunslingers’ decisions, so it doesn’t matter who they had aimed at.)

Additionally, if there are multiple optimal targets that would lead to the same winning chance, they will aim at the earliest gunslinger in the original input order. (E.g. If $G_1$, $G_4$, and $G_5$ are all optimal targets, the current gunslinger will aim at $G_1$ because $1 < 4 < 5$.) All gunslingers are aware of the preference for aiming at earlier-input-order gunslingers.

Calculate the winning chances for each gunslinger if all of them aim by the given rules.

Example

Explanation of Sample 2:
$G_1$ is guaranteed to lose, because no matter which other gunslinger they eliminate, the other gunslinger will immediately eliminate $G_1$ afterwards. Because aiming at either $G_2$ or $G_3$ yields the same optimal winning chance for $G_1$ (which is 0%), $G_1$ chooses to aim at $G_2$. $G_2$ is eliminated because $G_1$ cannot miss, so the turn goes to $G_3$. $G_3$ has only one valid target and eliminates $G_1$, leaving $G_3$ as the guaranteed winner.

\includegraphics[width=10cm]{sample2.png}
Figure 1: $G_1$ shoots at $G_2$, then $G_3$ shoots at $G_1$, leaving $G_3$ as the winner.

Input

The first line of input contains the integer $2 \leq n \leq 10$, the number of gunslingers.
The second line of input contains $n$ decimal numbers with up to two decimal places, $0 < h_1, h_2, \ldots , h_ n \leq 1$, where $h_ i$ is chance for $G_ i$ to hit their target.

Output

Output should contain $n$ lines.
The $i{\text {th}}$ line should contain the probability that $G_ i$ wins the duel. Values must be within $10^{-6}$ of the correct answer to be accepted.

Sample Input 1 Sample Output 1
2
0.5 0.5
0.6666666667
0.3333333333
Sample Input 2 Sample Output 2
3
1.0 1.0 1.0
0.0
0.0
1.0
Sample Input 3 Sample Output 3
4
1.0 0.5 1.0 1.0
0.0
0.0
0.0
1.0
Sample Input 4 Sample Output 4
4
0.9 0.9 0.5 0.8
0.0424424460
0.0671465764
0.2986148178
0.5917961598

Please log in to submit a solution to this problem

Log in