2023 Huawei OD Machine Test Paper C [Vaulting Horse Question] Java Implementation

Table of contents

topic

Ideas

Code


topic

Input two numbers m and n, m and n represent an m*n chessboard. Enter the data on the chessboard. There are two kinds of characters on the chessboard: numbers and ".". If it is a number, it means that the position is a horse. If it is ".", it means that the position is empty. In the chessboard The number represents the maximum number of steps that the horse can take.

For example, if a number is k at a certain position on the chessboard, it means that the knight can only move 1~k steps.

The movement of the knight on the chessboard is similar to the movement of the knight in Chinese chess. It first moves one square horizontally or vertically, and then moves it to a diagonal position.

Horses on the chessboard can move to the same position, and there can be multiple horses in the same position.

Can you please move all the knights on the chessboard to the same position? If possible, please enter the minimum number of moves. If not possible, output 0.

Input description
Enter two numbers, m and n. m and n represent an m*n chessboard. Enter the data on the chessboard.

Output Description
Can all the knights on the chessboard be moved to the same position? If so, please enter the minimum number of steps to move. If you can’t lose

Supongo que te gusta

Origin blog.csdn.net/misayaaaaa/article/details/135018519
Recomendado
Clasificación