#P2324. [SCOI2005] 骑士精神

    ID: 1302 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索2005四川各省省选启发式搜索启发式迭代加深搜索,IDA*A*算法

[SCOI2005] 骑士精神

Description

On a 5×55 \times 5 board there are 1212 white knights and 1212 black knights, plus one empty cell. At any time, a knight may move into the empty cell following the knight's move (it can move to a cell where the x-coordinate differs by 11 and the y-coordinate differs by 22, or the x-coordinate differs by 22 and the y-coordinate differs by 11).

Given an initial board, how can it be transformed, via moves, into the following target board:

To embody the "knight's spirit", they must finish in the minimal number of moves.

Input Format

The first line contains a positive integer TT (T10T \le 10), indicating there are TT test cases.

Then follow TT matrices of size 5×55 \times 5, where 0 denotes a white knight, 1 denotes a black knight, and * denotes the empty cell. There is no blank line between two test cases.

Output Format

For each test case, output one line. If the target state can be reached within 1515 moves (inclusive), output the minimal number of moves; otherwise, output -1.

2
10110
01*11
10111
01001
00000
01011
110*1
01110
01010
00100

7
-1

Hint

Translated by ChatGPT 5