← 返回 meta 的题目列表Maze Path Finding
类型:online_judge
Given a 2D maze maze of 0/1 where 0 is empty and 1 is a wall, a start cell start = (sr, sc) and a destination cell destination = (dr, dc).
You can move in 4 directions. From the current cell, the ball rolls in the chosen direction until it is about to hit a wall or boundary, and then it stops at the last valid empty cell. Only when it stops can you choose a new direction.
Return whether the ball can stop exactly at destination.
Input format
Line 1: integers m n
Next m lines: n integers (0/1)
Next line: sr sc
Next line: dr dc
Output
true or false
Constraints
1 <= m, n <= 100
maze[sr][sc] = 0, maze[dr][dc] = 0
Sample tests 1)
5 5
0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 0 0 0 0
0 4
4 4
=> true 2)
5 5
0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 0 0 0 0
0 4
3 2
=> false 3)
1 1
0
0 0
0 0
=> true 4)
2 2
0 1
0 0
0 0
1 1
=> false 5)
3 4
0 0 0 0
1 1 0 1
0 0 0 0
0 0
2 3
=> true
Example
Input
5 5
0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 0 0 0 0
0 4
4 4
Output
true