#B3809. Three Views of Cube Arrangement
Three Views of Cube Arrangement
Three Views of Cube Arrangement
Given a rectangular region on the ground with length n cm and width m cm, the region is divided into n × m small cells. Each cell (denoted by an integer pair \((x, y)\) where x is the column number from left to right and y is the row number from front to back) can have at most one cube of side length 1 cm placed on it.
The observer is positioned as shown in the figure and is looking toward the positive y direction. Based on the \(x, y, z\) axes orientation:
- The projection on the x-y plane (i.e. the top view or "from above") is obtained by observing which cells contain a cube.
- The projection on the y-z plane (i.e. the left view, observed from the left side looking right) is obtained by checking each row (i.e. each y coordinate): if at least one cube exists in that row, then the corresponding position in the left view is 1, otherwise 0.
- The projection on the x-z plane (i.e. the front view, observed from the front looking backward) is obtained by checking each column (i.e. each x coordinate): if there is a cube in any row for that column, then the front view at that column is 1, otherwise 0.
Your task is to compute these three views given the placement of the cubes in the region. The output should contain:
- The top view: an m × n matrix (m rows and n columns) where each element is 1 if a cube is placed in that cell, otherwise 0. The rows are printed in the order from front (y=1) to back (y=m).
- A blank line.
- The left view: a single row consisting of m numbers separated by a single space, where the i-th number (for y=i) is 1 if there is at least one cube in row i, otherwise 0.
- A blank line.
- The front view: a single row consisting of n numbers separated by a single space, where the j-th number (for x=j) is 1 if there is at least one cube in column j, otherwise 0.
Input Format:
The first line contains two integers n and m (n cm length, m cm width). The second line contains an integer k indicating the number of cubes placed. Then follow k lines, each with two integers x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m), representing the position of a cube.
Output Format:
Print the three views in order:
- The top view: m lines with n numbers each (separated by a single space).
- A blank line.
- The left view: a single line with m numbers (separated by a single space).
- A blank line.
- The front view: a single line with n numbers (separated by a single space).
inputFormat
The first line contains two integers n and m.
The second line contains an integer k, representing the number of cubes.
Each of the next k lines contains two integers x and y, indicating that there is a cube placed at cell (x, y).
outputFormat
Output the three views as described above:
- Top view: m lines each containing n numbers (0 or 1) separated by spaces.
- A blank line.
- Left view: a single line with m numbers separated by spaces.
- A blank line.
- Front view: a single line with n numbers separated by spaces.
sample
3 4
5
1 1
1 3
3 1
3 3
3 4
1 0 1
0 0 0
1 0 1
0 0 1
1 0 1 1
1 0 1
</p>