UVa OJ 1609 - Foul Play
Problem
n支队伍(2≤n≤1024,且n是2的整数幂)打淘汰赛,每轮都是两两配对,胜者进入下一轮。每支队伍的实力固定,并且已知每两支队伍之间的一场比赛结果。你喜欢1号队。虽然它不一定是最强的,但是它可以直接打败其他队伍中的至少一半,并且对于每支1号队不能直接打败的队伍t,总是存在一支1号队能直接打败的队伍t’使得t’能直接打败t。问:是否存在一种比赛安排,使得1号队夺冠?
Input
For each test case, the input is as follows:
-
One line containing the number of teams n, where n is a power of two and 2 ≤ n ≤ 1024. Teams are numbered from 1 to n, where team 1 is your favourite team.
-
n lines, each containing a string of n binary digits.
The k-th digit on the j-th line is ‘1’ if team j would certainly win from team k, otherwise it is ‘0’. A team cannot play against itself, therefore the j-th digit on the j-th line is ‘0’. If j!=k, the k-th digit on the j-th line is different from the j-th digit on the k-th line.
Output
For each test case, print n − 1 lines of output, specifying a tournament schedule that ensures victory for team 1.
The first n/2 lines describe the first round of the tournament. The next n/4 lines describe the second round, if any, etc. The last line describes the final match.
Each line contains two integers x and y, indicating that team x plays a match against team y.
If there are multiple tournament schedules where team 1 wins, any one of those tournament schedules will be accepted as a correct answer.
Sample Input
1 | 4 |
Sample Output
1 | 1 3 |
Solution
先把1队能打败的和不能打败的队伍全部区分开来,然后让不能打败的队伍和能被打败的队伍先互相匹配。接着对1匹配能打败的队伍。再让不能打败的队伍相互之间互相匹配,剩下的就随便匹配。每一次能减少一半的队伍,循环几次即可
1 |
|