#P4082. [USACO17DEC] Push a Box P
[USACO17DEC] Push a Box P
Description
Translated from USACO 2017 December Contest, Platinum Problem 2: Push a Box.
A barn is an rectangular grid, and some cells contain hay bales. Bessie stands in one cell, and a large crate occupies another cell. Bessie cannot be in the same cell as the crate, nor in the same cell as a hay bale.
From any empty cell, she may move to any of its four orthogonally adjacent cells (north, south, east, west). If she attempts to move into the cell containing the crate, the crate is pushed one cell further in the same direction, provided the next cell in that direction is within bounds and empty (i.e., not a hay bale or outside the grid); otherwise, the move is not allowed. After a successful push, Bessie occupies the crate’s previous cell.
Given the barn layout (empty cells, hay bales, and the crate), along with Bessie’s starting position and the target positions for the crate, determine whether Bessie can push the crate to each specified target cell.
Input Format
The first line contains three integers , where is the number of rows, is the number of columns, and is the number of queries.
The next lines describe the initial layout of the barn, where . denotes an empty cell, # denotes a hay bale, A denotes Bessie’s initial position, and B denotes the crate’s initial position.
The next lines each contain a coordinate , representing row and column . For each line, determine whether Bessie can push the crate to this cell.
Output Format
Output lines. For each query, print YES if Bessie can push the crate to the specified cell; otherwise, print NO.
5 5 4
##.##
##.##
A.B..
##.##
##.##
3 2
3 5
1 3
5 3
NO
YES
NO
NO
Hint
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5
京公网安备 11011102002149号