[Huawei OD machine test real question python] The perimeter of the same number forming a graph [2023 Q1 | 200 points]

Description of topic

The perimeter of the figure formed by the same number

Fill numbers, the same numbers form a solid figure, as shown in the following figure is a part of the matrix (blank means filling 0):
 

The number 1 forms a solid figure with a blue border, and the number 2 forms a solid figure with a red border.
The side length of a cell is specified as 1 unit.
According to the input, calculate the perimeter of each solid circle filled with non-zero values.

Input description:
input N in the first line, indicating N graphics, N > 0 and N < 64 × 64, the
cell coordinates in the upper left corner of the matrix are marked as (0, 0), the first number indicates the row number, and the second number indicates Column number
Next is N rows. The first number in each row is the number filled in the matrix cell, and each subsequent group of two indicates the coordinates of the cell filled with the number. Answerers do not need to consider the scene where the data format is illegal
. Investigate the data format
. The use case of the topic ensures that there will only be one line of input data for the same filling value.
Output description:
A total of N values ​​​​are output,
and each value represents a certain line of input. 1 number is the circumference of the first input figure, the second number is the circumference of the second input figure, and so on.

Use case 1:

enter:

<

Guess you like

Origin blog.csdn.net/xiao_pengjy/article/details/130334279