#P5372. [SNOI2019] 积木
[SNOI2019] 积木
Description
There is a grid board with rows and columns, where both and are odd. Some bricks are tiled on the grid. Bricks can be rotated and cannot overlap. There are bricks in total, which means there is exactly one empty cell on the board.
You can perform two kinds of operations:
- Rotate a brick that is adjacent to the empty cell (sharing a common edge) by into the empty cell.
- Translate a brick that is adjacent to the empty cell into the empty cell.
As shown in the figure (the moved brick is in a lighter color):

Please use the two operations above to transform the given grid board into the specified target state.
Input Format
The first line contains two positive odd integers , representing the number of rows and columns of the grid.
Then follow lines, each containing characters, describing the initial state of the grid board:
<means this cell is the left half of a brick.>means this cell is the right half of a brick.nmeans this cell is the upper half of a brick.umeans this cell is the lower half of a brick.omeans this cell is empty.
Then follow another lines, each containing characters, describing the target state you need to transform the board into, in the same format as above.
Output Format
You need to output a string that represents your operations in order:
Lmeans you moved the brick on the left side of the empty cell.Rmeans you moved the brick on the right side of the empty cell.Umeans you moved the brick above the empty cell.Dmeans you moved the brick below the empty cell.
Of course, if there are no operations, output an empty string.
3 3
nnn
uuu
o<>
<>n
<>u
<>o
URLR
5 5
n<><>
un<>n
nuonu
u<>un
<><>u
<><>o
<><>n
<><>u
<><>n
<><>u
RLLRLRR
Hint
Constraints and Notes
The length of your output operation sequence must not exceed .
For all testdata, .
- For of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For the remaining of the testdata, there are no special restrictions.
SPJ Notes
See https://www.luogu.org/discuss/show/114298. Thanks to @M_sea for the contribution.
Translated by ChatGPT 5
京公网安备 11011102002149号