Soccer
InterviewTime limit1sMemory limit128 MB
Given 16 teams, a fixed bracket, and pairwise win probabilities, compute each team's probability of winning the single-elimination tournament.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Probability, Implementation, Math
- Solved
- No attempts yet
Problem
Imagine a Soccer World Cup. After the group stage, 16 countries remain, and the champion is decided by the following single-elimination tournament. (The country names in the bracket below are only an example; the actual input may use different names.)
1 Germany ----+
+-- ? --+
2 Sweden -----+ |
+-- ? --+
3 Argentina --+ | |
+-- ? --+ |
4 Mexico -----+ |
+-- ? --+
5 Italy ------+ | |
+-- ? --+ | |
6 Australia --+ | | |
+-- ? --+ |
7 Switzerl ---+ | |
+-- ? --+ |
8 Ukraine ----+ |
+-- World Champion
9 England ----+ |
+-- ? --+ |
10 Ecuador ----+ | |
+-- ? --+ |
11 Portugal ---+ | | |
+-- ? --+ | |
12 Holland ----+ | |
+-- ? --+
13 Brazil -----+ |
+-- ? --+ |
14 Ghana ------+ | |
+-- ? --+
15 Spain ------+ |
+-- ? --+
16 France -----+
For every possible match A vs. B among these 16 nations you are given the probability that team A beats team B. Your task is to determine, for each nation, its probability of becoming world champion.
Input
The first line contains the number of scenarios. For each scenario, the first 16 lines give the names of the 16 countries, from top to bottom according to the structure above; each name is a single string of at most 10 letters. Next comes a integer matrix , where element is the probability, in percent, that the -th country defeats the -th country in a direct match. For example, means that in a match between Germany and Brazil, Germany wins with probability 57%. Matches never end in a draw, so for all .
Output
For each scenario, the output begins with a line Scenario #i:, where is the scenario number starting from 1. Then print 16 lines, each of width 17: the country's name on the left and, on the right, its probability of becoming world champion in percent, rounded to two decimal places, with the gap between them filled by space characters. Keep the countries in the same order as the input. Separate consecutive scenarios with a single blank line.