【P084】立体图

Time Limit: 1 second
Memory Limit: 50 MB

【问题描述】

小渊是个聪明的孩子,他经常会给周围的小朋友们讲些自己认为有趣的内容。最近,他准备给小朋友们讲解立体图,请你帮他画出立体图。
小渊有一块面积为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≤每个格子上的积木数≤50)。

【输出格式】

包含题目要求的立体图,是一个K行L列的字符矩阵,其中K和L表示最少需要K行L列才能按规定输出立体图。

【输入样例】

3 4
2 2 1 2
2 2 1 1
3 2 1 2

【输出样例】

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=P084

【题意】

【题解】

先处理出只有一个正方体的情况;
->从坐标(x,y)开始往右上角填充1个正方体;
然后剩下的就是根据坐标反复用那个函数填充正方体就好;
注意一下坐标的细节就好;
模拟题啦

【完整代码】

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1000;
const int maxn = 50 + 10;

char t[N][N];

int m, n,mx=1,my=1;
int a[maxn][maxn];
bool bo[N][N];

void o()
{
    rep2(i, mx, 1)
    {
        rep1(j, 1, my)
        {
            if (t[i][j] == ' ')
            {
                if (bo[i][j])
                    putchar(' ');
                else
                    putchar('.');
            }
            else
                putchar(t[i][j]);
        }
        puts("");
    }
}

void get_one(int x, int y)
{
    t[x][y] = '+';
    t[x][y+1] = t[x][y+2] = t[x][y+3] = '-'; t[x][y+4] = '+';
    t[x+1][y] = t[x+2][y] = '|', t[x+3][y] = '+';
    t[x+3][y+1] = t[x+3][y+2] = t[x+3][y+3] = '-'; t[x+3][y+4] = '+';
    t[x+1][y+4] = t[x+2][y+4] = '|';
    rep1(i, x+1, x+2)
        rep1(j, y + 1, y + 3)
        {
            t[i][j] = ' ';
            bo[i][j] = true;
        }
     t[x + 4][y+1] = '/';
     //t[x + 4][y] = '.',
    //t[x + 5][y] = t[x + 5][y+1] = '.';
    t[x + 5][y+2] = '+';
    rep1(i, 1, 3)
        t[x + 5][y+i + 2] = '-';
    t[x + 5][y + 6] = '+';
    t[x + 4][y + 5] = '/';
    rep2(i, x + 4, x + 3)
        t[i][y + 6] = '|';
    t[x + 1][y + 5] = '/';
    t[x + 2][y + 6] = '+';
    my = max(my, y + 6);
    mx = max(mx, x + 5);
    t[x + 2][y + 5] = t[x + 3][y + 5] = ' ';
    bo[x + 2][y + 5] = bo[x + 3][y + 5] = true;
    rep1(j, y + 2, y + 4)
    {
        t[x + 4][j] = ' ';
        bo[x + 4][j] = true;
    }
}

void input_data()
{
    rei(m), rei(n);
    rep1(i, 1, m)
        rep1(j, 1, n)
        rei(a[i][j]);
}

void get_ans()
{
    int nowx = 2 * m - 1, nowy = 2 * m - 1;
    rep1(i, 1, m)
    {
        rep1(j, 1, n)
        {
            int tx = nowx, ty = nowy;
            while (a[i][j]--)
            {
                get_one(tx, ty);
                tx += 3;
            }
            nowy += 4;
        }
        nowx = nowy = (m - i) * 2 - 1;
    }
}

void init()
{
    rep1(i, 1, N - 1)
        rep1(j, 1, N - 1)
        t[i][j] = ' ';
}

int main()
{
//  freopen("F:\\rush.txt", "r", stdin);
    init();
    input_data();
    get_ans();
    //前后关系
    //后(x1,y1),前(x1-2,y1-2);
    //先弄后面那个

    //左右关系
    //左:(x1,y1),右(x1,y1+4)
    //先左后右

    //上下关系
    //下(x1,y1),上(x1+3,y1);
    //先下后上
    o();
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(162)  评论(0编辑  收藏  举报