[Huawei OD machine test real test python] Habitable planet transformation plan [2023 Q2 | 200 points]

Title description

【Livable Planet Transformation Plan】

In 2XXX, humans conducted a livable transformation analysis on the atmosphere of Mars, making Mars theoretically suitable for human habitation;

Due to technical reasons, it is not possible to completely transform the Martian atmosphere at one time, and can only be done through local processing;

Assume that the area to be terraformed on Mars is a row * column grid. Each grid has 3 values, habitable zone, terraformable zone, and dead zone. Use YES, NO, and NA instead:

Enter description

YES means that the grid has completed atmospheric transformation;
NO means that the grid has not been transformed and can be transformed later;
NA means the dead zone, which is not used to judge whether the transformation is completed and cannot be passed through;
under initialization, this area may exist Multiple livable zones, and each livable zone can simultaneously spread to adjacent grids in the four directions up, down, left, and right of each solar day unit, automatically transforming the adjacent vacuum zones in the four directions into habitable areas;

Please calculate whether all the transformable areas in the grid of the area to be transformed can be turned into habitable areas. If so, return the number of solar days for the transformation. If not, return -1.

Input
Enter row * column grid data. The enumeration value of each grid value is as follows: YES, NO, NA;

Example:

YES YES NO
NO NO NO
NA NO YES

Output description

Guess you like

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