3D-Buildings

Time Limit: 1000 MS
Memory Limit: 32768 K
Description

Doctor Tang is an excellent Architect. Before awarded “the greatest Architect”, he needs to help government design a building group. The secret of mayor gives the Doctor Tang a map of platform,

2 2 1 2
2 2 1 1
3 2 1 2

which means there are buildings on every unit square. Each number means the height of the building.

Then, Doctor Tang is supposed to design a draft in 3D-view like those.
<p align="center"></p>
The first picture is viewed form the front, and the second is from the left.

We define every layer of a building follow the same format strictly. In order to show you the space, I turn it into a point on the picture. But you should just print the point you need to print. That’s means the point on the square shouldn’t be print. Here are some simple examples:
<p align="center"> </p>
The empty places decorate with “.”. Can you help Doctor Tang solving this problem? Just clam down, the problem is not as difficult as it seems.</td>

Input
There are multiple test cases. For each test case, the first line has two integers: N, M. Following N lines, each line has M integers h1,h2…hm, describing the height of building in this position.
(1<=N<=50, 1<=M<=100, 1<=hi<=100)

Output
For each test case, print a 3D-view viewing from the front and from the left.

Sample Input

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

Sample Output

......+---+---+...+---+
..+---+  /   /|../   /|
./   /|-+---+ |.+---+ |
+---+ |/   /| +-|   | +
|   | +---+ |/+---+ |/|
|   |/   /| +/   /|-+ |
+---+---+ |/+---+ |/| +
|   |   | +-|   | + |/.
|   |   |/  |   |/| +..
+---+---+---+---+ |/...
|   |   |   |   | +....
|   |   |   |   |/.....
+---+---+---+---+......
........+---+...+---+
......./   /|../   /|
......+---+ |.+---+ |
......|   +---+   | +
....+---+/   /|-+ |/|
.../   /+---+ |/|-+ |
..+---+-|   | + |/| +
./   /  |   |/| + |/.
+---+---+---+ |/| +..
|   |   |   | + |/...
|   |   |   |/| +....
+---+---+---+ |/.....
|   |   |   | +......
|   |   |   |/.......
+---+---+---+........

题目大意

输入 n m  以及nxm的位置中方块的数量。。。。

然后输出 正视图和左视图。。。。

无聊模拟啊。。。 比赛的时候建系错误 导致没AC 然后内存开始没想大多给的超大...

//还有很多可以优化的地方。。。 写的非常撮
#include
#include

int mp[55][105];
char p[1000][1000];
int n,m,height;
int prtx,prty;

void draw(int x,int y){
    p[x][y+1]=p[x][y+2]=p[x][y+3]=p[x+3][y+1]=p[x+3][y+2]=p[x+3][y+3]=p[x+5][y+3]=p[x+5][y+4]=p[x+5][y+5]='-';
    p[x][y]=p[x][y+4]=p[x+3][y]=p[x+3][y+4]=p[x+5][y+2]=p[x+5][y+6]=p[x+2][y+6]='+';
    p[x+1][y]=p[x+2][y]=p[x+1][y+4]=p[x+2][y+4]=p[x+3][y+6]=p[x+4][y+6]='|';
    p[x+4][y+1]=p[x+1][y+5]=p[x+4][y+5]='/';
    p[x+1][y+1]=p[x+2][y+1]=p[x+1][y+2]=p[x+2][y+2]=p[x+1][y+3]=p[x+2][y+3]=p[x+4][y+2]=p[x+4][y+3]=p[x+4][y+4]=p[x+2][y+5]=p[x+3][y+5]=' ';
}
void print(int xx,int yy){
    for(int i=xx;i>=0;i--){
        for(int j=0;j<=yy;j++){
            putchar(p[i][j]);
        }
        putchar('\n');
    }
}
int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
        int x,y;
        height=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                scanf("%d",&mp[i][j]);
                if(mp[i][j]>height)height=mp[i][j];
            }
        }

        memset(p,'.',sizeof(p));
        prtx=prty=0;
        for(int k=0;k<height;k++){
            for(int i=0;i<n;i++){//draw zhengshitu
                for(int j=0;j<m;j++){                     if(mp[i][j]>k){
                        x=(n-i-1)*2+k*3;
                        y=j*4+(n-i-1)*2;
                        draw(x,y);
                    //printf("i=%d\t j=%d\t h=%d\t\tx:%d\ty:%d\t\n",i,j,k,x,y);
                        if(prtx < x+5)prtx=x+5;
                        if(prty < y+6)prty=y+6;
                    }
                }
            }
        }
        print(prtx,prty);
        //output
        prtx=prty=0;
        memset(p,'.',sizeof(p));
        //printf("%d%dn",n,m);
        for(int k=0;k<height;k++){             for(int i=m-1;i>=0;i--){//draw zhengshitu
                for(int j=0;j<n;j++){                     if(mp[j][i]>k){
                        //printf("i:%dtj:%dth:%dtn",i,j,k);
                        x=i*2+k*3;
                        y=j*4+i*2;
                        draw(x,y);
                        //printf("i=%d\t j=%d\t h=%d\t\tx:%d\ty:%d\t\n",i,j,k,x,y);
                        if(prtx < x+5)prtx=x+5;
                        if(prty < y+6)prty=y+6;
                    }
                }
            }
        }
        print(prtx,prty);
        //output

    }
    return 0;
}
原创文章采用 CC BY-NC-SA 4.0协议 进行许可,转载请著名转自: Hrbust 1966 3D-Buildings 模拟