#K37117. Valid Seating Arrangement
Valid Seating Arrangement
Valid Seating Arrangement
You are given a positive integer n representing the number of guest pairs. Each pair has two guests who are "plus-ones" of each other. The task is to determine a seating arrangement for all 2n
guests such that no pair of plus-ones sits directly next to each other (neighbors in the seating order).
If n = 1
, output No valid seating arrangement
because it is impossible to seat a single pair apart.
For any n > 1
, a valid seating arrangement is guaranteed to exist. The arrangement should be output as a sequence of numbers (from 1 to 2n) representing guest identifiers in the order they are seated. The arrangement is obtained by listing the numbers in increasing order and then performing a series of swaps to ensure that no two adjacent guests are from the same pair. Hint: For guests, consider that the pairings are (1,2), (3,4), (5,6), …, (2n-1,2n).
Note: All input must be read from standard input, and all output must be printed to standard output.
inputFormat
The input consists of a single integer n
(1 ≤ n ≤ 103) provided on a single line from standard input.
outputFormat
If n = 1
, output the string No valid seating arrangement
. Otherwise, output a valid seating arrangement as 2n
space-separated integers on a single line, representing the guests' seating order.
1
No valid seating arrangement
</p>