#P3341. [ZJOI2014] 消棋子
[ZJOI2014] 消棋子
Description
Remove Pieces is an interesting game. The game is played on an board. Each cell of the board is either empty or contains a piece of some color. Each color appears exactly twice. In each round, the player can choose an empty cell and choose two directions among up, down, left, and right. If, in each of the two chosen directions, there exists a cell containing a piece, and the first piece encountered along each direction has the same color, then we take away those two pieces, and call this a legal move. Otherwise, the move is illegal and the game will not process this move. The goal is to remove as many pieces as possible.
Given such a game and a person's sequence of moves, you need to:
- State how many pieces this person can remove.
- Provide a sequence of moves that removes the maximum number of pieces.
Input Format
The first line gives the integers , .
The second line gives the integer , the number of different colors.
The next lines, the -th line contains four integers , meaning that the two cells of color are .
Then an integer follows, the number of this person’s moves. The next lines each contain two integers and two letters, representing the chosen cell and the two directions. We use to denote up, down, left, and right, respectively.
Output Format
The first line outputs how many pieces this person can remove.
The second line contains an integer , the number of moves in your sequence.
The next lines each contain two integers and two letters, representing your chosen cell and the two directions.
4 4
4
1 1 1 4
1 2 3 4
1 3 3 2
4 1 2 3
6
2 3 U R
2 1 D R
2 2 L R
2 4 L D
3 1 L R
3 3 L U
2
4
4 3 L U
3 3 L U
3 2 R U
1 2 L R
Hint
For all testdata, , and it is guaranteed that in the answer the number of operations satisfies .
Translated by ChatGPT 5
京公网安备 11011102002149号