【题目描述】
小渊是个聪明的孩子,他经常会给周围的小朋友讲些自己认为有趣的内容。最近,他准备给小朋友讲解立体图,请你帮他画出立体图。
小渊有一块面积为m*n的矩形区域,上面有m*n个边长为1的格子,每个格子上堆了一些同样大小的积木(积木的长宽高都是1),小渊想请你打印出这些格子的立体图。我们定义每个积木为如下格式,并且不会做任何翻转旋转,只会严格以一种形式摆放。
+---+
/ /|高
+---+ |
| | +
| |/宽
+---+
长
每个顶点用1个加号"+"表示,长用3个"-"表示,宽用1个"/"表示,高用两个"|"表示。符号"+","-","/","|"的ASCII码分别是43,45,47,124。字符"."(ASCII码46)需要作为背景输出,即立体图中的空白部分需要用"."来代替。立体图的画法如下面的规则:
若两块积木左右相邻,图示为:
..+---+---+
./ / /|
+---+---+ |
| | | +
| | |/.
+---+---+..
若两块积木上下相邻,图示为:
..+---+
./ /|
+---+ |
| | +
| |/|
+---+ |
| | +
| |/.
+---+..
若两块积木前后相邻,图示为:
....+---+
.../ /|
..+---+ |
./ /| +
+---+ |/.
| | +..
| |/...
+---+....
立体图中,定义位于第(m,1)的格子(即第m行第1列的格子)上面的自底向上的第一块积木(即最下面的一块积木)的左下角顶点为整张图最左下角的点。
【输入】
第一行有用空格隔开的2个整数m和n,表示有m*n个格子(1<=m,n<=50)。
接下来的m行,是一个m*n的矩阵,每行有n个用空格隔开的整数,其中第i行第j列上的整数表示第i行第j列的格子上摞有多少个积木(1<=每个格子上的积木数<=100)。
【输出】
包含题目要求的立体图,是一个K行L列的字符矩阵,其中K和L表示最少需要K行L列才能按规定输出立体图。
【输入样例】
3 4
2 2 1 2
2 2 1 1
3 2 1 2
【输出样例】
......+---+---+...+---+
..+---+ / /|../ /|
./ /|-+---+ |.+---+ |
+---+ |/ /| +-| | +
| | +---+ |/+---+ |/|
| |/ /| +/ /|-+ |
+---+---+ |/+---+ |/| +
| | | +-| | + |/.
| | |/ | |/| +..
+---+---+---+---+ |/...
| | | | | +....
| | | | |/.....
+---+---+---+---+......
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define PDD pair<double,double>
#define x first
#define y second
using namespace std;
const int N=1e3+5,mod=1e9+7;
int a[N][N],h=1000,w=0;
char s[N][N];
char c[10][10]={
"..+---+",
"./ /|",
"+---+ |",
"| | +",
"| |/.",
"+---+.."
};
void init()
{
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
s[i][j]='.';
}
void push(int x,int y)
{
h=min(h,x-5);
w=max(w,y+6);
x-=5;
for(int i=0;i<6;i++)
for(int j=0;j<7;j++)
if(c[i][j]!='.') s[x+i][y+j]=c[i][j];
}
void pull()
{
for(int i=h;i<=1000;i++)
{
for(int j=0;j<=w;j++)
cout<<s[i][j];
cout<<endl;
}
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
init();
int n,m;
cin>>n>>m;
int mx=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[i][j],mx=max(mx,a[i][j]);
for(int i=0;i<n;i++)
for(int j=0;j<=m;j++)
for(int k=1;k<=mx;k++)
{
int x=1000-2*(n-i-1)-(k-1)*3;
int y=4*j+(n-i-1)*2;
if(a[i][j]>=k) push(x,y);
}
pull();
return 0;
}