France '98
InterviewTime limit1sMemory limit128 MB
Given win probabilities for every pair of 16 teams and a fixed bracket, compute each team's probability of winning the single-elimination tournament.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Probability, Implementation, Simulation
- Solved
- No attempts yet
Problem
The first round of the Soccer World Cup in France has just finished, and 16 nations remain. The champion is now decided by the following single-elimination tournament:
1 Brazil --------+
+---+
2 Chile ---------+ |
+---+
3 Nigeria -------+ | |
+---+ |
4 Denmark -------+ |
+---+
5 Holland -------+ | |
+---+ | |
6 Yugoslavia ----+ | | |
+---+ |
7 Argentina -----+ | |
+---+ |
8 England -------+ |
+-- World Champion
9 Italy ---------+ |
+---+ |
10 Norway --------+ | |
+---+ |
11 France --------+ | | |
+---+ | |
12 Paraguay ------+ | |
+---+
13 Germany -------+ |
+---+ |
14 Mexico --------+ | |
+---+
15 Romania -------+ |
+---+
16 Croatia -------+
For every possible match A vs. B among these 16 nations you are given the probability that team A beats team B. Together with the bracket above, this is enough to compute the probability that any given nation wins the World Cup. For example, if Germany beats Mexico with probability 80%, Romania beats Croatia with 60%, Germany beats Romania with 70%, and Germany beats Croatia with 90%, then the probability that Germany reaches the semi-finals is .
Write a program that computes each of the 16 nations' chances of becoming World Champion.
Input
The input consists of a single test case.
The first 16 lines list the names of the 16 nations, from top to bottom in the order shown in the bracket above (one name per line).
Then follows a integer matrix . Element is the probability, in percent, that nation # beats nation # in a direct match. Nation # is the -th nation from top to bottom in the list. In the bracket above Brazil is #1 and Germany is #13, so would mean that in a match between Brazil and Germany, Brazil wins with probability 55%.
Matches never end in a draw, so for all .
Output
Print 16 lines, one per nation, in the same order as the input. Each line has the form <name> p=Y.YY%: the nation's name left-justified in a field of width 10, then a single space, then p=, then the nation's chance of winning the cup as a percentage rounded to exactly two decimal places, then %.