The Rotation Game
题目描述
The rotation game uses a # shaped board, which can hold $24$ pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly $8$ pieces of each kind.
Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration.
题意概述
给定一个包含$24$个格子的井字形棋盘,其中恰有$8$个 1、$8$个 2 和$8$个 3。要求通过$8$种操作使得中间八个格子上的数字相同。求在操作数最小的情况下字典序最小的操作方案。
算法分析
如果用三进制表示状态进行 BFS,那么空间肯定不够。这时可以用时间换空间,进行 IDA*。有两个剪枝:不进行上次操作的逆操作;无论如何也不能在规定深度内完成时直接退出。
代码
1 |
|