Codey and Schedule
https://www.hackerrank.com/contests/codenection-2023-final-round-closed-category/challenges/cn-c12
Question
Codey is the chairman of a competition with n teams and the game cannot start without a schedule. Due to time constraints, Codey wants to arrange a schedule with a minimal number of rounds so that each of the n team will play against two different teams. Help Codey arrange the schedule!
Output m, which represents the number of rounds, and m pairs of integers and , which represent the -th match up in the schedule. It is guaranteed that the answer exists.
Note that this problem uses a custom checker, so make sure your program compiles correctly and prints the output according to the format before submitting.
Input Format
The first line contains an integer n, which represents the number of teams.
Constraints
Output Format
Output an integer m, which represents the number of rounds, for the first line.
In the following m lines, output pairs of integers and , where , representing the -th matchup in the schedule.
If there are multiple answers, you may output any of them.
It is guaranteed that the answer exists.
Sample Inputs:
Input
5Output
5
3 2
3 4
5 1
5 4
2 1Explanation
There are 5 rounds in total.
In the first round, team 3 will play against team 2.
In the second round, team 3 will play against team 4.
In the third round, team 5 will play against team 1.
In the fourth round, team 5 will play against team 4.
In the fifth round, team 2 will play against team 1.
Last updated