← 返回 uber 的题目列表Tournament Results by Player Ranks
类型:online_judge
You are given an integer array ranks where ranks[i] is the rank of player i. Match outcomes are determined solely by rank: in a 1v1 match, the player with the higher rank (larger number) wins (adjust if you remember a different rule). The tournament is single-elimination: in round 1, players are paired in the given order (0 vs 1, 2 vs 3, ...); winners advance to the next round, where they are paired again in order, until a champion is produced.
Output the tournament results:
winner_index (index in the original array)
winner_rank
All rounds' matchups and winners for bracket replay.
Input (stdin)
Line 1: integer n
Line 2: n integers, the ranks
Output (stdout)
First line: winner_index winner_rank
Then for each round, one line:
number of matches m
followed by m triples (a,b,w) meaning players a vs b, winner w
Constraints
1 <= n <= 2^17
n is a power of two
0 <= ranks[i] <= 1e9
Example Input: 4 5 1 3 7 Output: 3 7 Round1: (0,1,0) (2,3,3) Round2: (0,3,3)
Example
Input
4
5 1 3 7
Output
3 7
2 (0,1,0) (2,3,3)
1 (0,3,3)