#P13654. [CERC 2020] Excavation
[CERC 2020] Excavation
题目描述
The police investigation revealed the gangsters deployed several radioactive stones under the city to poison underground waters. The exact positions of radioactive stones were found, but due to nature of radioactivity, it is a difficult task to remove the stones safely. The government of the city thus decided to use shielded excavators to retrieve stones from the ground.
The city shape is a square grid. City services have several excavator types available – Reepadlo, Qrtech, Bugger, Namakatschenko, and Kopatsch. Each of them has different specifications and movement pattern. Excavators may move either as a Rook, a Queen, a Bishop, a kNight, or as a King in the game of chess, respectively (see images for movement illustration). Due to compatibility issues only a single type of excavators can be deployed.
There is at most one radioactive stone on each tile of the grid. At the beginning of the excavation, there is one excavator at the position of each radioactive stone and it immediately retrieves the stone from the ground. The next steps of the operation are executed to follow strict radiation handling safety protocol. At each step only one excavator can execute a single move and it can execute it only if the move brings the excavator to a position of another excavator. Excavators of types Reepadlo, Qrtech, Bugger may skip over other excavators during a move over multiple grid tiles, i.e. they do not have to end the move on the position of the first encountered excavator. After excavator arrives to the position of excavator , takes its load and is removed from the operation to be cleaned of radiation.
The operation finishes successfully if in the end there is a single excavator remaining. It is possible the operation can not be successfully finished.
Your task is to determine whether the operation can be finished successfully. If it can, print also the excavators' moves leading to the solution.
输入格式
The first line of input contains an integer (), determining the size of the city, and a single character determining the excavator type to be deployed (“R” – Reepadlo, “Q” – Qrtech, “B” – Bugger, “N” – Namakatschenko, “K” – Kopatsch).
After that follow lines describing the initial positions of the excavators in the city. Each line contains characters, where each character is either the excavator type or “.” for empty field. There is always at least one excavator deployed in the city.
输出格式
On the first line print either “YES”, if the operation for the given configuration can be finished successfully, and “NO” otherwise. If the operation can be finished successfully, print also lines describing moves of excavators in the same order they were executed during the excavation, if there were any. -th such line describes a single step and contains four space separated integers (), indicating an excavator moves from position to position in step . A position describes the position on row (numbered from top to bottom) and in column (numbered from left to right).
2 K
K.
KK
YES
2 2 2 1
2 1 1 1
3 B
B..
B..
..B
NO