#P2739. [USACO4.4] 棋盘游戏 Shuttle Puzzle

[USACO4.4] 棋盘游戏 Shuttle Puzzle

Description

In the shuttle puzzle of size 33, there are 33 white pieces, 33 black pieces, and a wooden box with 77 cells arranged in a line. The 33 white pieces are placed on one end, the 33 black pieces are placed on the other end, and the middle cell is empty.

  • Initial state: WWW_BBB (_ represents the empty cell)
  • Goal state: BBB_WWW

Two types of moves are allowed in this game:

  • You may move a piece into the adjacent empty cell.
  • You may jump a piece over exactly one adjacent piece of the opposite color into the empty cell.

The shuttle puzzle of size NN has NN white pieces, NN black pieces, and a wooden box with 2N+12N+1 cells.

Here is a solution for the size 33 puzzle, including the initial state, intermediate states, and the goal state:

WWW_BBB \rightarrow WW_WBBB \rightarrow WWBW_BB \rightarrow WWBWB_B \rightarrow WWB_BWB \rightarrow W_BWBWB \rightarrow _WBWBWB \rightarrow BW_WBWB \rightarrow BWBW_WB \rightarrow BWBWBW_ \rightarrow BWBWB_W \rightarrow BWB_BWW \rightarrow B_BWBWW \rightarrow BB_WBWW \rightarrow BBBW_WW \rightarrow BBB_WWW

Write a program to solve the shuttle puzzle of size NN (1N121 \le N \le 12). The number of moves must be minimized.

Input Format

A single integer NN, the size of the shuttle puzzle.

Output Format

Output the sequence of positions on the board of the piece to be moved before each move (positions are numbered from left to right as 1,2,,2N+11, 2, \dots, 2N+1). Print 2020 numbers per line (the last line may contain fewer than 2020 numbers).

Among all solutions with the minimum number of moves, the output should be lexicographically smallest, i.e., if there are multiple optimal solutions, choose the one with the smallest first number; if still tied, the smallest second number; and so on.

3
3 5 6 4 2 1 3 5 7 6 4 2 3 5 4

Hint

Problem translation from NOCOW.

USACO Training Section 4.3.

Translated by ChatGPT 5