P27855 [洛谷] [Language Monthly Contest 202307] Three-View Projection
普及
题目描述

Problem Description

All content related to the $x, y, z$ axes and directions is based on the following $x, y, z$ axes, positions, and viewing directions. The observer is standing at the position shown in the figure, looking towards the positive direction of the $y$ axis (green line, arrow direction).

There is a rectangular area on the ground with a length and width (extending along the $x, y$ axes) of $n \text{ cm}, m \text{ cm}$. We divide this area into $n \times m$ small grids. Each grid can hold a small cube with a side length of $1 \text{ cm}$.

We use an integer pair $(x, y)$ to represent the position of a grid in space, which represents the $x$-th grid from left to right and the $y$-th grid from front to back.

For example, in the $3 \times 4$ area shown above, from the observer's position, the plane defined by the red and blue lines ($x, z$ axes) is the front, the plane defined by the blue and green lines ($y, z$ axes) is the left side, and the plane defined by the red and green lines ($x, y$ axes) is the bottom. The positions of the five small cubes are $(1, 1), (1, 3), (3, 1), (3, 3), (3, 4)$.

The three-view projection is a set of drawings made by an observer from three different angles: from above (top view), from the left (left view), and from the front (front view), to observe the same spatial geometric shape.

For example, the above images are the three-view projections of the example area.

Given a region and the arrangement of cubes within it, please help calculate the three-view projections of this region.

Input Format

The input consists of $n + 1$ lines.

The first line contains two integers $n, m$, representing the length and width of the rectangular area.
The next $n$ lines, each containing $m$ integers, describe the arrangement of cubes. The integer $a_{x, y}$ at the $x$-th row and $y$-th column represents the status of the grid $(x, y)$. If $a_{x, y} = 1$, it means there is a small cube in that grid; otherwise, there is no cube.

Output Format

The output consists of $2 + m$ lines.

The first line contains $n$ integers, representing the front view from left to right. If there is a filled position in the front view, output $1$; otherwise, output $0$. Integers in the same line are separated by a single space.
The second line contains $m$ integers, representing the left view from back to front. If there is a filled position in the left view, output $1$; otherwise, output $0$. Integers in the same line are separated by a single space.
The next $m$ lines, each containing $n$ integers, represent the top view from back to front and left to right. If there is a filled position in the top view, output $1$; otherwise, output $0$. Integers in the same line are separated by a single space.

The directions mentioned above are based on the observer's initial standing position and direction. If you are confused about the output order, please refer to the sample to aid your understanding.

Sample Input and Output

Input Sample #1

3 4
1 0 1 0
0 0 0 0
1 0 1 1

Output Sample #1

1 0 1
1 1 0 1
0 0 1
1 0 1
0 0 0
1 0 1

Input Sample #2

10 7
0 1 0 0 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 0 1 0 1 0 0
0 1 1 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0

Output Sample #2

1 1 0 0 1 1 1 1 1 0
0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 1 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0
1 0 0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0 1 0

Notes

Sample 1 Explanation

Sample 1 is the example given in the problem.

Data Size and Constraints

For $100\%$ of the data, it is guaranteed that $1 \leq n, m \leq 200$ and $0 \leq a_{x, y} \leq 1$.

Test Case Number $n$ $m$ $a_{x, y}$
$1$ $= 1$ $= 1$ No special restrictions
$2 \sim 4$ $\leq 10$ $\leq 10$ No special restrictions
$5 \sim 6$ $\leq 200$ $= 1$ No special restrictions
$7$ $\leq 200$ $\leq 200$ $= 1$
$8 \sim 10$ $\leq 200$ $\leq 200$ No special restrictions
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4 1 0 1 0 0 0 0 0 1 0 1 1
样例输出
1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1