#P1379. 八数码难题

    ID: 374 远端评测题 1000ms 125MiB 尝试: 4 已通过: 1 难度: 6 上传者: 标签>搜索福建省历届夏令营枚举,暴力哈希,HASHA*算法

八数码难题

Description

On a 3×33\times 3 board, there are eight tiles, each labeled with a digit from 11 to 88. One cell is left empty and is denoted by 00. A tile adjacent to the blank can be moved into the blank. The task is: given an initial layout (initial state) and a target layout (to simplify the problem, the target state is set to 123804765123804765), find a sequence of moves with the minimum number of steps to transform the initial state into the target state.

Input Format

Input the initial state: nine numbers in one line, with the blank denoted by 00.

Output Format

Output a single line containing one integer, the minimum number of moves required to reach the target state from the initial state. It is guaranteed that in the testdata there are no unsolvable initial states.

283104765

4

Hint

Sample Explanation

In the figure, the cell labeled 00 is the blank. The green cell is the position of the blank, and the orange cells are the positions that can be moved into the blank in the next step. As shown, the target state can be reached in four moves.

Moreover, it can be proven that no better strategy exists.

Translated by ChatGPT 5