Output Contest Matches
Description
Given n teams numbered 1 to n, pair them for matches so stronger teams meet weaker first. Output the bracket format.
Examples
n = 4"((1,4),(2,3))"The bracket matching algorithm pairs the strongest team (rank 1) with the weakest (rank n), second strongest with second weakest, and so on. This greedy pairing is applied recursively: after forming n/2 pairs in round one, these pairs become the new 'teams' for the next round, creating nested parentheses until only one match remains.
n = 2"(1,2)"This is the smallest possible tournament with only 2 participants. They are directly paired against each other, so the bracket is simply (1,2).
n = 16"((((1,16),(8,9)),((4,13),(5,12))),(((2,15),(7,10)),((3,14),(6,11))))"With 16 participants, the tournament creates a more complex nested structure. The pairing follows the pattern where team 1 pairs with team n, team 2 with team n-1, and so on, then these pairs are recursively grouped into larger brackets.
Constraints
- •
n is power of 2, 2 ≤ n ≤ 2¹²