Huawei OD computer test-maze problem (C++ & Java & JS & Python)

describe

Define a two-dimensional array N*M, as shown below for a 5 × 5 array:


int maze[5][5] = {
0, 1, 0, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0,
};


It represents a maze, in which 1 represents the wall and 0 represents the path that can be walked. It can only be walked horizontally or vertically, not diagonally. It requires programming to find the route from the upper left corner to the lower right corner. The entry point is [0,0], that is, the first grid is the way to go.

Data range: 2≤�,�≤10 2≤n,m≤10, the input content only contains 0≤���≤1 0≤val≤1 

Enter description:

Enter two integers, representing the number of rows and columns of the two-dimensional array respectively. Then enter the corresponding array, where 1 represents the wall and 0 represents the path that can be taken. The data guarantees a unique solution, regardless of the situation of multiple solutions, that is, there is only one passage in the maze.

Output description:

The shortest path from the upper left corner to the lower right corner, the format is as shown in the example.

Example 1

enter:

5 5
0 1 0 0 0
0 1 1 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0

Output:

(0,0)
(1,0)
(2,0)
(2,1)
(2,2)
(2,3)
(2,4)
(3,4)
(4,4)

Example 2

enter:

5 5
0 1 0 0 0
0 1 0 1 0
0 0 0 0 1
0 1 1 1 0
0 0 0 0 0

Output:

 

Supongo que te gusta

Origin blog.csdn.net/m0_68036862/article/details/132805229
Recomendado
Clasificación