2023 Huawei od machine test real test paper B volume [weekend mountain climbing] C++ implementation

Table of contents 

topic

train of thought

Code


topic

On weekends, Xiao Ming is going to climb a mountain for exercise. 0 represents flat land, and the height of a mountain is represented by 1 to 9. Each time Xiao Ming climbs or descends a mountain, the height difference can only be within k or less.
Enter the description from the upper left corner (0,0)
The first line enters mnk (separated by spaces). Represents the two-dimensional mountain map of m*n, k is the maximum value of Xiaoming's height difference each time he climbs or descends the mountain

Then enter the mountain map, a total of m rows and n columns, all separated by spaces. Value range:
0< m <= 500
0<n<=500
0<k<5
Output description
Ask Xiaoming how high the highest peak can be climbed, and the shortest steps to the highest peak , the output is separated by spaces.
Peaks with the same height will output shorter steps. If there is no mountain to climb, the height and steps will return 0

Example 1:

enter

5 4 1
0 1 2 0
1 0 0 0
1 0 1 2
1 3 1 0
0 0 0 9
output

2 2
Explanation
According to the mountain map, the highest peak that can be climbed is at (0,2) position࿰

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/131948090