#P7367. [CTSC2002] 丹奇方块【征集 SPJ】
[CTSC2002] 丹奇方块【征集 SPJ】
Description
The game is played on an unbounded board. There is a black obstacle at the center . Not far away, there are gray blocks, each placed on a distinct cell whose coordinates are odd.
The task of the game is to glue all gray blocks together to form a given shape, as shown in Figure 1. The shape may appear anywhere on the board, but it cannot be rotated or mirrored. Figure 2 shows a valid initial state, where there is one gray block at each of .
Each time, the player may issue one of four move commands: up (U), down (D), left (L), or right (R), causing all gray blocks to move one cell simultaneously in the specified direction. If there is an obstacle directly in front of a block, only that block cannot move, while the other blocks still move normally. For example, starting from the state in Figure 2 and applying the commands LLUR will produce the layout shown in Figure 3. Once a situation like Figure 3 occurs, where two or more blocks are adjacent, these adjacent blocks will immediately glue together into an inseparable whole. In future moves, as long as any block in this whole has an obstacle in front of it, the entire whole cannot move, even if the other blocks are not blocked. Then, from the state in Figure 3, applying the commands URD will produce Figure 4. Since the gray blocks in Figure 4 form exactly the target shape, the game ends in victory.

This game looks simple, but when there are many blocks and the target shape is complex, the player often needs many steps to finish. Jiajia hopes to find a solution within steps. Can you help him?
Input Format
The first line contains an integer , the number of blocks.
The second line contains integer pairs , where the -th pair represents the initial position of the -th block. The positions are listed in order from top to bottom (i.e. increasing ), and from left to right (i.e. increasing ).
The third line contains integer pairs , representing the relative positions of each small block in the target shape. The target is guaranteed to be a single connected whole, and the testdata always has a solution.
Output Format
The first line is the required number of steps . The second line is the move sequence.
3
-1 -1 1 -1 1 1
1 1 2 1 2 2
7
LLURURD
Hint
Constraints
For of the testdata, , , and are odd. Also, .
Sample Explanation
According to the input format, in this problem the D direction is the positive direction of the axis, and the R direction is the positive direction of the axis. Therefore, the sample explanation can refer to the third paragraph of the problem description.
Translated by ChatGPT 5
京公网安备 11011102002149号