#P11463. n-Player Basketball Pass
n-Player Basketball Pass
n-Player Basketball Pass
In this problem, there are (n) players arranged in a row and numbered from (1,2,\dots,n) (with (n) guaranteed to be odd). Initially, the ball is held by the middle player, i.e. the player numbered (\frac{n+1}{2}). The game proceeds for (k) passes according to the following rules:
-
For the first pass, the middle player chooses a direction (x) (where (x = 0) indicates left and (x = 1) indicates right). He passes the ball to the nearest player in the chosen direction. Immediately after passing, the middle player is removed from his current position in the row and reinserted at the left end (if passing left) or at the right end (if passing right).
-
For each subsequent pass, the new middle player (i.e. the player currently at position (\lfloor \frac{n}{2} \rfloor + 1)) must choose the direction opposite to the previous pass, and then he passes the ball to the adjacent player in that direction. After the pass, he is removed from the row and reinserted at the corresponding end (left if he passed left; right if he passed right).
After (k) passes, output the final arrangement of players (from leftmost to rightmost).
Example: For (n = 3) with initial pass direction (x = 0) (left) and (k = 3) passes, the simulation is as follows:
- Initial arrangement (pass 0): 1 2 3 (ball with player 2)
- Pass 1: Player 2 passes left to player 1, then is reinserted at the left end. New arrangement: 2 1 3
- Pass 2: Now, player 1 (middle) passes right (opposite direction) to player 3, then is reinserted at the right end. New arrangement: 2 3 1
- Pass 3: Now, player 3 (middle) passes left (opposite of last pass) to player 2, then is reinserted at the left end. Final arrangement: 3 2 1
inputFormat
The input consists of three space-separated integers on a single line:
(n) (x) (k)
where (n) is the odd number of players ((3 \leq n \leq 10^5) or as specified), (x) is the initial direction (0 for left and 1 for right), and (k) is the number of passes.
outputFormat
Output the final arrangement of the players as a sequence of (n) integers separated by spaces.
sample
3 0 3
3 2 1