#P6391. [COCI 2007/2008 #4] KOCKE
[COCI 2007/2008 #4] KOCKE
Problem Description
In a 2D Cartesian coordinate system, there is a robot located at the point . Each time, it can move one grid cell up, down, left, or right. There are also magnets located at different positions.
Each time the robot moves, it can push the magnet in the destination cell. However, when two magnets have a face touching each other (that is, they are on adjacent coordinates), they will attract each other and form a single whole. Pushing any one of them will have the same effect on the whole group.
You need to give one movement plan for the robot such that, after moving, these magnets form a T shape (rotation is not allowed).
Input Format
The input consists of lines. Each line contains two integers , describing the position of one magnet.
The testdata guarantees that no two magnets are on the same coordinate or on adjacent coordinates.
Output Format
Output one line with a string representing the magnet-moving plan. The moves are:
L: move one cell to the left;R: move one cell to the right;U: move one cell up;D: move one cell down.
At most steps.
0 1
-1 0
1 0
0 -1
0 -3
DRRUUULLDD
-2 0
-1 -1
0 -2
1 0
0 1
URRDLLURUULDDLLLDR
Hint
Constraints
For of the testdata, it is guaranteed that .
Notes
This problem is translated from COCI2007-2008 CONTEST #4 T6 KOCKE.
Thanks to @一扶苏一 for providing the SPJ!
Translated by ChatGPT 5