#P2739. [USACO4.4] 棋盘游戏 Shuttle Puzzle
[USACO4.4] 棋盘游戏 Shuttle Puzzle
Description
In the shuttle puzzle of size , there are white pieces, black pieces, and a wooden box with cells arranged in a line. The white pieces are placed on one end, the 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 has white pieces, black pieces, and a wooden box with cells.
Here is a solution for the size puzzle, including the initial state, intermediate states, and the goal state:
WWW_BBB WW_WBBB WWBW_BB WWBWB_B WWB_BWB W_BWBWB _WBWBWB BW_WBWB BWBW_WB BWBWBW_ BWBWB_W BWB_BWW B_BWBWW BB_WBWW BBBW_WW BBB_WWW
Write a program to solve the shuttle puzzle of size (). The number of moves must be minimized.
Input Format
A single integer , 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 ). Print numbers per line (the last line may contain fewer than 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
京公网安备 11011102002149号