Projection Area of 3D Shapes
The problem asks for the total area of three projections of the grid containing cubes. Here’s the Python function:
|
|
Explanation
The function calculates the total area of three projections:
xy_projection (Top View): We look from the top. Any cell with one or more cubes will contribute 1 to the projection. Thus, we count the number of cells with value greater than 0.
yz_projection (Front View): We look from the front. Each column’s contribution to the projection is the maximum value in that column. We take the maximum value from each column and sum them.
zx_projection (Side View): We look from the side. Each row’s contribution to the projection is the maximum value in that row. We take the maximum value from each row and sum them.
Finally, we add the three projections to get the total area.