#T369. 迷宫
迷宫
Description
One day, while exploring the forest, Extense accidentally wandered into a maze. The maze can be seen as consisting of an n * n grid, where each grid point has only two states: . and #. The former indicates a passable path, while the latter indicates an impassable obstacle.
When Extense is at a certain grid point, he can only move to one of the four adjacent grid points in the north, south, east, or west directions (i.e., up, down, left, or right). Extense wants to move from point A to point B. The question is whether he can do so without leaving the maze. If either the starting point or the destination is impassable (marked as #), it is considered impossible to achieve.
Input Format
The first line contains the number of test cases k, followed by k sets of input.
For each test case:
- The first line is a positive integer
n(1 ≤ n ≤ 100), indicating that the maze is of sizen * n. - The next
nlines form ann * nmatrix, where each element is either.or#. - The following line contains four integers
ha,la,hb,lb, describing that point A is located at rowha, columnla, and point B is located at rowhb, columnlb. Note thatha,la,hb, andlbare all zero-indexed.
Output Format
Output k lines, each corresponding to an input. Print "YES" if it is possible to reach point B from point A, otherwise print "NO".
2
3
.##
..#
#..
0 0 2 2
5
.....
###.#
..#..
###..
...#.
0 0 4 0
YES
NO