这题是普及组的题…………但是 ………… 毕竟模拟硬伤
我的想法是这样的: 读入矩阵之后,从左上角开始填,原则是从上往下,从左往右,,从前往后,对图进行填充,从上往下填就不能从1开始,因为会造成RE访问非法内存的情况,建完会有一些地方重合或者多出来,就需要加一个合并操作。至于‘.’的情况,我是写了个函数,传的坐标是立方体的前视图的左上角坐标,然后暴力处理vis数组,最后暴力处理‘.’和起止点。模拟不是考复杂度……不讨论复杂度。。。。。。
琳琳飒飒两百行,做完的时候也没空压代码了,抽空再打一遍的时候可以压代码试试。
我的程序TYVJ数据可以过,TYVJ评测机抽了但是数据还是有的,codevs数据过不去 不知原因……方法很暴力。
还有 我写了几个没用的函数,是合并别的情况的,这里是写着很爽就写了~
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int size = 200;
int num[55][55];
char ans[size][size];
int abs(int x)
{
if(x < 0) return -x;
return x;
}
bool vis[size][size];
int cnt;
struct point{int x,y;}poi[2510];
void build(int x,int y)
{
ans[x][y] = ans[x][y+4] = '+';
ans[x][y+1] = ans[x][y+2] = ans[x][y+3] = '-';
ans[x+3][y] = ans[x+3][y+4] = '+';
ans[x+3][y+1] = ans[x+3][y+2] = ans[x+3][y+3] = '-';
ans[x+1][y] = ans[x+2][y] = ans[x+1][y+4] = ans[x+2][y+4] = '|';
ans[x-1][y+1] = ans[x-1][y+5] = '/';
ans[x-2][y+2] = ans[x-2][y+6] = '+';
ans[x-2][y+3] = ans[x-2][y+4] = ans[x-2][y+5] = '-';
ans[x+2][y+5] = '/';
ans[x+1][y+6] = '+';
ans[x][y+6] = ans[x-1][y+6] = '|';
vis[x][y+6] = vis[x-1][y+6] = 1;
vis[x][y] = vis[x][y+4] = 1;
vis[x][y+1] = vis[x][y+2] = vis[x][y+3] = 1;
vis[x+3][y] = vis[x+3][y+4] = 1;
vis[x+3][y+1] = vis[x+3][y+2] = vis[x+3][y+3] = 1;
vis[x+1][y] = vis[x+2][y] = vis[x+1][y+4] = vis[x+2][y+4] = 1;
vis[x-1][y+1] = vis[x-1][y+5] = 1;
vis[x-2][y+2] = vis[x-2][y+6] = 1;
vis[x-2][y+3] = vis[x-2][y+4] = vis[x-2][y+5] = 1;
vis[x+2][y+5] = 1;
vis[x+1][y+6] = 1;
vis[x][y+6] = vis[x-1][y+6] = 1;
vis[x-1][y+2] = vis[x-1][y+3] = vis[x-1][y+4] = 1;
vis[x+1][y+1] = vis[x+2][y+1] = vis[x+2][y+2] = vis[x+1][y+2] = vis[x+1][y+3] = vis[x+2][y+3] = 1;
vis[x][y+5] = vis[x+1][y+5] = 1;
}
void merge1(int x1,int y1,int x2,int y2)//前后 x1下
{
ans[x1+1][y1+1] = ans[x1+2][y1+1] = ans[x1+2][y1+2] = ans[x1+1][y1+2] = ans[x1+1][y1+3] = ans[x1+2][y1+3] = ' ';
ans[x1-1][y1+2] = ans[x1-1][y1+3] = ans[x1-1][y1+4] = ' ';
ans[x2-1][y2+2] = ans[x2-1][y2+3] = ans[x2-1][y2+4] = ' ';
ans[x2][y2+5] = ans[x2+1][y2+5] = ans[x1][y1+5] = ans[x1+1][y1+5] = ' ';
}
void merge2(int x1,int y1,int x2,int y2)//上下,x1下
{
ans[x1+1][y1+1] = ans[x1+2][y1+1] = ans[x1+2][y1+2] = ans[x1+1][y1+2] = ans[x1+1][y1+3] = ans[x1+2][y1+3] = ' ';
ans[x1][y1+5] = ans[x1+1][y1+5] = ' ';
ans[x2+1][y2+1] = ans[x2+2][y2+1] = ans[x2+2][y2+2] = ans[x2+1][y2+2] = ans[x2+1][y2+3] = ans[x2+2][y2+3] = ' ';
ans[x2][y2+5] = ans[x2+1][y2+5] = ' ';
ans[x2-1][y2+2] = ans[x2-1][y2+3] = ans[x2-1][y2+4] = ' ';
}
void merge3(int x1,int y1,int x2,int y2)//横向 x1为 ←
{
ans[x1+1][y1+1] = ans[x1+2][y1+1] = ans[x1+2][y1+2] = ans[x1+1][y1+2] = ans[x1+1][y1+3] = ans[x1+2][y1+3] = ' ';
ans[x1-1][y1+2] = ans[x1-1][y1+3] = ans[x1-1][y1+4] = ' ';
ans[x2+1][y2+1] = ans[x2+2][y2+1] = ans[x2+2][y2+2] = ans[x2+1][y2+2] = ans[x2+1][y2+3] = ans[x2+2][y2+3] = ' ';
ans[x2-1][y2+2] = ans[x2-1][y2+3] = ans[x2-1][y2+4] = ' ';
ans[x2][y2+1] = ans[x2+1][y2+1] = ' ';
}
int main()
{
//从下往上 从前往后 从左往右
/* build(5,5);
/*build(5,9);
merge3(5,5,5,9);
for(int i = 1;i <= 15;i ++)
{
for(int j = 1;j <= 15;j ++)
{
cout<<ans[i][j];
}
cout<<endl;
}*/
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i ++)
for(int j = 1;j <= m;j ++)
{
scanf("%d",&num[i][j]);
}
for(int i = 1;i <= m;i ++) //i是列,j是行
{
int xs = 100;
int ys = 100 + (i-1) * 4;
for(int j = 1;j <= n;j ++)
{
if(j != 1) ys -= 2;
if(j != 1) xs += 2;
int lastx,lasty;
int build_start_x = 0;
int build_start_y = 0;
for(int v = 1;v <= num[j][i];v ++)
{
lastx = build_start_x,lasty = build_start_y;
build_start_x = xs - (v-1)*3;
build_start_y = ys;
// poi[++cnt].x = build_start_x,poi[++cnt].y = build_start_y;
build(build_start_x,build_start_y);
// if(lastx != 0 && lasty != 0)
// {
merge2(lastx,lasty,build_start_x,build_start_y);
// }
}
}
}
for(int i = 1;i <= 200;i ++)
{
for(int j = 1;j <= 200;j ++)
{
if(vis[i][j] == 0)
{
ans[i][j] = '.';
}
}
}
int stax,stay,endx,endy;
for(int i = 1;i <= 200;i ++)
{
bool flag = 0;
for(int j = 1;j <= 200;j ++)
{
if(ans[i][j] != '.') {flag = 1; break;}
}
if(flag == 1)
{
stax = i;
break;
}
}
for(int j = 1;j <= 200;j ++)
{
bool flag = 0;
for(int i = 1;i <= 200;i ++)
{
if(ans[i][j] != '.') {flag = 1; break;}
}
if(flag == 1)
{
stay = j;
break;
}
}
for(int i = 200;i >= 1;i --)
{
bool flag = 0;
for(int j = 200;j >= 1;j --)
{
if(ans[i][j] != '.') {flag = 1; break;}
}
if(flag == 1)
{
endx = i;
break;
}
}
for(int i = 200;i >= 1;i --)
{
bool flag = 0;
for(int j = 200;j >= 1;j --)
{
if(ans[j][i] != '.') {flag = 1; break;}
}
if(flag == 1)
{
endy = i;
break;
}
}
for(int i = stax;i <= endx;i ++)
{
for(int j = stay;j <= endy;j ++)
{
cout<<ans[i][j];
}
cout<<endl;
}
return 0;
}
//这真TM是普及组的题?
//graph