#P5699. [NOI2008] 赛程安排
[NOI2008] 赛程安排
Problem Description
With the Olympics approaching, students are becoming more and more enthusiastic about sports. As NOI2008 is coming, the school is planning to hold a table tennis tournament. Student Z, a hardcore table tennis fan, sees this as a great chance to show his skills, so he eagerly signs up.
This table tennis tournament uses a single-elimination format: winners advance. There are exactly students signed up ( is an integer power of , so we may assume ). Therefore, after the first round, students will be eliminated and the other students will advance to the next round; after the second round, students advance to the next round, and so on, until after rounds the champion and runner-up are decided. Specifically, everyone has an initial ID from . Student Z has ID . All students have distinct IDs. They will be assigned to positions, and then play according to a bracket like the one below:

The figure above shows the bracket when .
To attract more students to participate, the prizes are very generous. A player eliminated in round will receive yuan, and the champion will receive the highest prize yuan. Clearly, the prizes satisfy .
In the warm-up matches before the official tournament, Student Z keeps losing. After careful analysis, he realizes the main reason is not his technique, but that the few students who beat him have playing styles that counter his. Once they face each other, he naturally loses. Student Z thinks: if only he could avoid these players in the official tournament!
Assume we know the win probabilities between every pair of players: the probability that player defeats player is (guaranteed that ). Student Z hopes to determine the matchups (reassign positions for all players) so that he can obtain as much prize money as possible in expectation. Can you help Student Z find an arrangement that maximizes his expected prize?
Input Format
This is an output-only problem. All input files match*.in are provided in the additional files.
The first line of match*.in contains a positive integer , the total number of participants. The data guarantees that there exists a non-negative integer such that .
Next come lines, each containing real numbers between and , , meaning the probability that player with ID defeats player with ID . Each real number is given to two digits after the decimal point. Note in particular that .
Next come lines, each containing one integer, giving the prizes for different rounds of advancement. The value on line is .
Output Format
The output file match*.out contains lines. The number on line is the ID of the student placed at position . Student Z’s ID must be placed at position .
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
1
4
2
3
Hint
Sample Explanation
After the first round, the probability that the player with ID (Student Z) advances is , the probability that the player with ID advances is , the probability that the player with ID advances is , and the probability that the player with ID advances is .
In the second round (the final), the probability that player (Student Z) wins both rounds is $80\%\times (60\%\times 70\%+40\%\times 60\%)=52.8\%$. Therefore, the probability that Student Z loses in the first round is , the probability that he wins the first round but loses in the second round is , and the probability that he becomes the champion is .
Thus, the expected prize is $0.2\times 1+(0.8-0.528)\times 2+0.528\times 3=2.328$.
How to Test Your Output
We provide checker to test whether your output file is acceptable.
After calling this program, checker will give the result based on your output file, including:
- Abnormal termination: unknown error.
Format error: output file format error.Not a permutation: the output file is not a permutation of .OK.Your answer is xxx: the output file is accepted, andxxxis the corresponding expected prize.
Scoring Method
Each test point is scored independently.
For each test point, if your output file is invalid (such as wrong format, or the output does not meet the requirements), you get points for that test point. Otherwise, let your expected prize be , and the reference expected prize be . We also have a scoring parameter . Your score for that test point is as follows:
- If , you get points.
- If , you get point.
- Otherwise, the score is:$$\left\lfloor\frac{\text{your\_ans}-\text{our\_ans}\times d}{\text{our\_ans}-\text{our\_ans}\times d}\times 8\right\rfloor+2$$
Special Note
Please keep the input files *.in and your outputs *.out properly, and back them up in time to avoid accidental deletion.
Additional Files
You need to compile and use checker by yourself.
Please go to Github to download the latest source code of testlib.h.
Translated by ChatGPT 5