Bessie and her friends have invented a new game. The game is named accurately, but not particularly
creatively. They call it the “Push A Box Around The Barn To Get It In The Right Spot And Don’t Move
The Hay” game (if you think that’s excessive, you should see some of the variable names the cows use
when they write code…)The barn can be modeled as an N×M rectangular grid. Some of the grid cells
have hay in them. Bessie occupies one cell in this grid, and a large wooden box occupies another ce
ll. Bessie and the box are not able to fit in the same cell at the same time, and neither can fit in
to a cell containing hay.Bessie can move in the 4 orthogonal directions (north, east, south, west) a
s long as she does not walk into hay. If she attempts to walk to the space with the box, then the bo
x will be pushed one space in that direction, as long as there is an empty cell on the other side. I
f there is no empty cell, then Bessie will not be able to make that move.A certain grid cell is desi
gnated as the goal. Bessie’s goal is to get the box into that location.Given the layout of the barn,
including the starting positions of the box and the cow, and the target position of the box, determ
ine if it possible to win the game.
The first line has three numbers, N, M, and Q,
where N is the number of rows in the grid and M is the number of columns.
On the next N lines is a representation of the grid,
where characters represent empty cells (.), hay (#),
Bessie’s starting position (A), and the box’s initial location (B).
This is followed by Q lines, each with a pair of integers (R,C).
For each pair, you should determine if it is possible to get the box to that cell at row R, column C,
starting from the initial state of the barn. The top row is row 1, and the left column is column 1.
Q lines, each with either the string “YES” or “NO”.
Sample Input
5 5 4






3 2

3 5

1 3

5 3
Sample Output




To push the box to the position (3, 5), the cow just needs to move 3 spaces to the right.

None of the other three positions are attainable.

设visit[x][y][i]表示箱子在x,y这个位置 人在箱子的i这个方向上 那么考虑如何不经过箱子到达箱子的另外一边 我们考虑 这样的点一定是在点双里 那么我们直接建出圆方树 然后判断的时候就看是否是 父亲的父亲 或者拥有 相同的父亲即可

mmp蒟蒻我bfs的时候 需要先标记vis表示是否在队列里 我基础这么菜?..


第二遍就是求答案 最后o(1)询问即可



辣鸡蒟蒻一枚qwq 欢迎加qq qwq 2922945330