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

PROGRAMMING:Find the shortest path of maze

Luz5年前 (2021-05-10)题库488
The total step size of the shortest path of the maze is solved recursively. Input a maze to find the shortest path length from the entrance to the exit. To simplify the problem, the maze uses two-dimensional array
Int maze [10] [10] to store the distribution of obstacles, assuming that the size of the maze's transverse and longitudinal dimensions are the same, and read by the program running. If the value of the maze size read in is n (3 < n < = 10), then the maze's transverse and longitudinal dimensions are n, and the outermost circle of the maze is an obstacle, maze [1] [1] is the entrance of the maze, maze [n-2] [n-2] is the exit, If maze [i] [J] = 1, it means that the position is an obstacle; if maze [i] [J] = 0, it means that the position is a walkable vacancy (0 < = I < = n-1, 0 < = J < = n-1). Find the shortest total step on the path from entrance maze [1] [1] to exit maze [n-2] [n-2]. The maze is only allowed to walk in the horizontal or up and down four directions, and the walking position cannot be repeated.
###Input format:
Enter the integer n of maze size, and a two-dimensional array of N rows and N columns (array element 1 represents obstacle, 0 represents vacancy)
###Output format:
If there is a feasible channel, an integer is output to represent the shortest step size of the channel; If there is no channel, output "no solution"
###Input example:
```in
ten
1 1 1 1 1 1 1 1 1 1
1 0 0 1 0 0 0 1 0 1
1 0 0 1 0 0 0 1 0 1
1 0 0 0 0 1 1 0 0 1
1 0 1 1 1 0 0 0 0 1
1 0 0 0 1 0 0 0 0 1
1 0 1 0 0 0 1 0 0 1
1 0 1 1 1 0 1 1 0 1
1 1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
```
The above input represents a maze as follows:
![ Png] (~ / b9cb4128-aeac-4e42-b6cf-b3a1b3c7f071. PNG)
The red small square is the obstacle, the blue small square is the vacancy, the white small circle is a passage from the entrance to the exit, and the two circles represent a step.
###Output example:
```out
fourteen
```







answer:If there is no answer, please comment