EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2023
  3. Final Round

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 aia_iai​ and bib_ibi​ , which represent the iii-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

3≤n≤1053 \le n \le 10^53≤n≤105

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 aia_iai​ and bib_ibi​, where ai≠bia_i \ne b_iai​=bi​, representing the iii-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

5

Output

5
3 2
3 4
5 1
5 4
2 1

Explanation

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.


Solution - Simplest Round Robin

Ignore all the descriptions, as they only to make you confuse about that.

Basically, all the question wants is, loop through array[n] vs array[n+1], then each team will guarantee that must have fought 2 different teams.

How it works? I draw the illustration, and you will understand:

Assume we have 2 identical arrays:
1 2 3 4 5
1 2 3 4 5
let's shift the second array to the left once:
1 2 3 4 5
2 3 4 5 1

Have you found the pattern? 
let's take team 1 as example, he will be facing 2 and 5;
take team 3 as example, he will be facing 4 and 5
...

And you will be find that, the amount of tries is exactly as same as the total team number.
This exactly solved the whole problem!

The only edge case we need to consider is explicitly print array[0] vs array[n] as array is not a cycle. That's it.

Now we found the procedure, now let's get into coding!

t = int(input().strip())
print(t)

for i in range(1, t+1):
    if(i >= t):
        print(t, "1")
    else:
        print(i, i+1)
PreviousCodey and ConnectionNextCodey and School Supplies

Last updated 2 months ago

šŸ‡²šŸ‡¾