#P1058. 3D Block Drawing
3D Block Drawing
3D Block Drawing
Little Obiyoshi is a clever kid who loves to share interesting things with his friends. Recently, he prepared a lesson on three‐dimensional drawings using blocks. He has an m×n rectangular grid. Each cell in the grid contains a stack of one or more cubical blocks with side length 1. All blocks are identical and are placed in the same orientation without any rotations or flips.
The drawing of each block must follow exactly the ascii art format below (with no extra spaces or rotations):
$$\def\arraystretch{1e-10} \begin{aligned} &\texttt{ +---+}\\ &\texttt{ / /|}\\ &\texttt{+---+ |}\quad\textsf{(height)}\\ &\texttt{| | +}\\ &\texttt{| |/ }\quad\textsf{(width)}\\ &\texttt{+---+ }\\ & \quad\textsf{(length)} \end{aligned} $$Notes about the drawing:
- Each vertex is drawn with the plus sign
+
(ASCII 43). - The long edge is drawn with three dashes
-
(ASCII 45). - The edge representing the width is drawn with a slash
/
(ASCII 47). - The edge representing the height is drawn with a vertical bar
|
(ASCII 124). - The background (empty area) must be filled with dot
.
(ASCII 46).
When adjacent blocks share a face they overlap; for example, the illustrations below show two blocks that are adjacent horizontally, vertically, and in depth. In the final drawing, the block that is located in the grid cell at (m,1) (i.e. the bottom‐left cell) has its lowest block drawn so that its left‐bottom vertex becomes the overall drawing’s bottom–left point.
Given the grid dimensions and the number of blocks in every cell, print the complete three–dimensional drawing.
Isometric Projection Details:
- For a single block the drawing occupies 6 rows and 7 columns.
- For a cell at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) with a stack height h, the drawing of each block in the stack is placed with a base offset computed as follows:
Base X offset = 4 × (j - 1).
Base Y offset = 2 × ((m - i) + (k - 1)) for the k-th block (1-indexed from the bottom).
Blocks must be drawn one by one onto a canvas (initially filled with dots) in the following order: iterate over rows from m down to 1 (so that cells closer to the front overwrite those in the back), and for each cell iterate over the blocks from bottom to top. When drawing each block, overlay its pattern onto the canvas – non-space characters in the block pattern replace what is already on the canvas.
The final drawing is then printed line by line from top (highest canvas row) to bottom.
inputFormat
The input begins with two integers m and n (1 ≤ m, n ≤ 10), which are the number of rows and columns respectively. Then follow m lines, each containing n integers. The j-th number in the i-th line indicates the number of blocks stacked in the cell at row i, column j (each block count is between 1 and 10). Note that the grid cell at (m,1) corresponds to the bottom–left cell in the drawing.
outputFormat
Output the complete three–dimensional drawing according to the rules described above. Make sure to fill unused spaces with dots .
.
sample
1 1
1
+---+
/ /|
+---+ |
| | +
| |/
+---+
</p>