National Olympiad in Informatics, China, 2008
With the Olympics right around the corner, students' interest in physical education is skyrocketing. As NOI 2008 approaches, the school is currently planning to host a ping-pong tournament. Beings a very avid ping-pong enthusiast, this is the perfect opportunity for little Z to show off his skills. Thus, he quickly registers himself and begins his intensive preparation.
The tournament will follow a single-elimination format where only the
winners of a round advance. There just happens to be (
is a power
of
, so we may as well let
) participating students. After
the first round,
students will be eliminated, and the
other
will advance to the next round. After the second
round, only
students will advance, and so on until
after round
, where the champion and runner-up will be determined.
Every contestant is assigned a number from
to
, where little Z is
contestant number
. The IDs of all students are unique, and all
students will be assigned to
slots. Then, the tournament process
will follow a structure like the one below.
Slot 1 | Slot 2 | Slot 3 | Slot 4 | Slot 5 | Slot 6 | Slot 7 | Slot 8 |
Winner of Slots 1 and 2 | Winner of Slots 3 and 4 | Winner of Slots 5 and 6 | Winner of Slots 7 and 8 | ||||
Winner of Slots 1, 2, 3, and 4 | Winner of Slots 5, 6, 7, and 8 | ||||||
Champion |
To attract more students, the prizes of the tournament are very
generous. The competitors being eliminated in round are awarded
dollars, and the champion will receive the largest prize of
dollars. Needless to say, the prize amounts will satisfy
.
In the warm-up rounds prior to the real tournament, little Z was repeatedly defeated. After some careful analysis, he concluded that the key reason behind his failure was not an issue of his skill, but was because the students who defeated him just happened to clash with his playing stylistically. Little Z thought to himself, how nice would it be if these students could be avoided in the actual tournament!
Let's assume that we already know the probabilities of winning for all
contestants in pairwise matches. The probability of contestant
winning against contestant
is
(where it is guaranteed
that
). Little Z wishes to know for a certain
tournament structure (by reassigning the slots for each contestant),
what is the largest possible prize that he can obtain. Can you help
little Z design a matching scheme for this tournament so that the
expectations for his prize money is as large as possible?
Input Specification
There are test cases
match1.in
to match10.in
that will be given to
your program (through standard input). They can be downloaded here for
you to study:
match.zip
The first line of each test case contains an integer from to
,
specifying the test case number (
matchx.in
will have x
on the first
line).
The second line contains a single integer , representing the total
number of contestants. The data guarantees that
will be a
nonnegative integer for
.
For the following lines, each line contains
real numbers
between
and
inclusive, representing the probability of
contestant
defeating contestant
. Each real value will be given
to two decimal places. Especially take note of when
.
For the following lines, each line contains an integer
describing the prize money for a particular round. The
-th of these
lines contain
.
Output Specification
Output lines, where line
represents the number of the contestant
that is matched to slot
. Little Z's number must be matched to the
first slot.
Sample Input
0
4
0.00 0.70 0.60 0.80
0.30 0.00 0.60 0.40
0.40 0.40 0.00 0.70
0.20 0.60 0.30 0.00
1
2
3
Sample Output
1
4
2
3
Explanation
After the first round is over, the probability for contestant (little
Z) to advance is
, the probability for contestant
to advance is
, the probability for contestant
to advance is
, and the
probability for contestant
to advance is
.
In the second round (the championship match), the probability of
contestant (little Z) winning the first two matches is
.
Thus, the probability of little Z losing his first
match is
, the probability of him winning the
first match but losing the second match is
,
and the probability of him being the champion is
.
From this, the expected value for his prize money is
.
Experimentation
We supply a tool match_check.py for you to test whether your solutions are accepted. The usage for this program is
match_check.py <input-file> <output-file>
When you execute match_check.py
, the program will process your input
and output files and print the result to standard output. Possible
results of the execution include:
Abnormal termination
: An unknown error occurred.Format error
: The output file is incorrectly formatted.Not a permutation
: The output file is not a permutation of the integers fromto
.
OK. Your answer is x
: The output will be accepted.will be the expected prize money.
Scoring
Each test case will be graded independently.
For each test case, if your output is illegal (i.e. has invalid
formatting, doesn't fit with the requirements, etc.) then you will
receive a score of 0.
Otherwise, if the expected prize money for your output is , the
prize money determined by the contest organizers' solution is
,
and a parameter for grading is
, then your score out of 10 for the
test case will be:
, if
.
, if
.
- Otherwise, your score will be:
Hint
"Expected Value"
The mathematical expected value is the most fundamental property of a
random variable. It reflects the size of the average value of a random
variable, also known as the expectation or mean. It is an extension of
the simple arithmetic mean, or a weighted average of all the possible
values. Ex. If a city has families,
of which do not have
children,
of which has one child,
of which have two
children, and
of which have three children, then the number of
children in a family within this city is a random variable that can take
on the values of
,
,
, or
. The probability for
children is
,
of
child is
, of
children is
, and of
children is
. Its
expected value is
, and therefore
the average family has
children.
To calculate the random variable for this problem, assume that little
Z's chances of losing the first round is , chances of winning
the first round but losing the second is
, the chances of winning
the first two rounds but losing the third is
, and so on. Then
the expected value for little Z's prize money is:
Problem translated to English by .
Comments