Your new company is building a robot that can hold small lightweight
objects. The robot will have the intelligence to determine if an
object is light enough to hold. It does this by taking pictures of the
object from the 6 cardinal directions, and then inferring an upper
limit on the object’s weight based on those images. You must write a
program to do that for the robot. You can assume that each object is
formed from an N N N lattice of cubes, some of which may be
missing. Each 1 1 1 cube weighs 1 gram, and each cube is painted a
single solid color. The object is not necessarily connected. Input The
input for this problem consists of several test cases representing
different objects. Every case begins with a line containing N , which
is the size of the object (1 N 10). The next N lines are the
different N N views of the object, in the order front, left, back,
right, top, bottom. Each view will be separated by a single space from
the view that follows it. The bottom edge of the top view corresponds
to the top edge of the front view. Similarly, the top edge of the
bottom view corresponds to the bottom edge of the front view. In each
view, colors are represented by single, unique capital letters, while
a period ( . ) indicates that the object can be seen through at that
location. Input for the last test case is followed by a line
consisting of the number ` 0 ‘. Output For each test case, print a
line containing the maximum possible weight of the object, using the
format shown below.
如果某个位置从两个方向上看不一样的话,那个位置一定没有方块。因为保证合法,所以一直删除直到没有矛盾即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
/*vis[1..6]:front,left,back,right,top,bottom*/
char clr[15][15][15],vis[10][15][15];
int n;
void rd()
{
int i,j,p;
char s[15];
for (i=1;i<=n;i++)
for (p=1;p<=6;p++)
{
scanf("%s",s+1);
for (j=1;j<=n;j++)
vis[p][i][j]=s[j];
}
}
void find(int p,int i,int j,int k,int &x,int &y,int &z)
{
switch (p)
{
case 1:
x=n-k+1;
y=j;
z=n-i+1;
break;
case 2:
x=j;
y=k;
z=n-i+1;
break;
case 3:
x=k;
y=n-j+1;
z=n-i+1;
break;
case 4:
x=n-j+1;
y=n-k+1;
z=n-i+1;
break;
case 5:
x=i;
y=j;
z=n-k+1;
break;
case 6:
x=n-i+1;
y=j;
z=k;
break;
}
}
void tem()
{
int i;
i++;
}
void init()
{
int p,i,j,k,x,y,z;
memset(clr,0,sizeof(clr));
for (p=1;p<=6;p++)
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (vis[p][i][j]=='.')
for (k=1;k<=n;k++)
{
find(p,i,j,k,x,y,z);
if (x==1&&y==1&&z==1) tem();
clr[x][y][z]='.';
}
}
bool make()
{
int p,i,j,k,x,y,z;
bool flag=0;
for (p=1;p<=6;p++)
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (vis[p][i][j]!='.')
{
k=1;
while (1)
{
find(p,i,j,k,x,y,z);
if (clr[x][y][z]!='.') break;
k++;
}
if (clr[x][y][z]&&clr[x][y][z]!=vis[p][i][j])
{
clr[x][y][z]='.';
flag=1;
}
else clr[x][y][z]=vis[p][i][j];
}
return flag;
}
int count()
{
int x,y,z,ret=0;
for (x=1;x<=n;x++)
for (y=1;y<=n;y++)
for (z=1;z<=n;z++)
if (clr[x][y][z]!='.') ret++;
return ret;
}
int main()
{
while (scanf("%d",&n)&&n)
{
rd();
init();
while (make());
printf("Maximum weight: %d gram(s)\n",count());
}
}