-->
当前位置:首页 > 题库

PROGRAMMING:Maze II

Luz5年前 (2021-05-10)题库383
A maze consists of N rows and m columns. Some of the lattices are open space and can walk; Some grid is an obstacle, can't walk; In addition, some grid is a closed door, you need to open the door to pass. Xiao Ming is going to walk from one grid (starting point) to another grid (ending point) in the maze, assuming that he can only move up, down, left and right, and can't walk obliquely. It takes one minute to move a position (grid) and one extra minute to open a door. Given the start and end of the maze and Xiaoming, please write a program to calculate the shortest time Xiaoming takes from the start to the end.
###Input format:
The input contains multiple sets of data. The first line of each set of data is two integers n and m ($$1 / Le m, N / Le 100 $$), representing the length and width of the maze. Then there are n rows, m numbers in each row, representing the whole maze. The open space grid is represented by 0, the obstacle is represented by 1, the door is represented by 2, the starting point of Xiaoming is represented by 3, and the ending point is represented by 4.
###Output format:
For each group of data, if it can reach the end point, output an integer to indicate the shortest time Xiaoming needs from the start point to the destination. If the destination cannot be reached, output "unreachable".
###Input example:
```in
5 5
1 0 1 1 1
1 0 4 1 0
1 0 0 1 2
0 0 2 1 0
1 0 3 0 1
5 5
3 0 1 1 1
1 0 1 1 0
1 0 1 1 2
0 0 2 1 0
1 0 1 0 4
```
###Output example:
```out
four
unreachable
```







answer:If there is no answer, please comment