# LA 2995 & ZOJ2714 Image is Everything

166人阅读 评论(0)

Image is Everything

Time Limit: 2 Seconds Memory Limit: 65536 KB

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.

Sample Input

3
.R. YYR .Y. RYY .Y. .R.
GRB YGR BYG RBY GYB GRB
.R. YRR .Y. RRY .R. .Y.
2
ZZ ZZ ZZ ZZ ZZ ZZ
ZZ ZZ ZZ ZZ ZZ ZZ
0


Sample Output

Maximum weight: 11 gram(s)
Maximum weight: 8 gram(s)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define FOR(i,n) for(int i=1; i<=n; i++)
#define FORDAO(i,n) for(int i=n; i>0; i--)
const int MAXN = 15;
char view[MAXN][MAXN][MAXN][10];
bool islive[MAXN][MAXN][MAXN];
int n;
{
char rt;
while(true)
{
rt = getchar();
if((rt>='A'&&rt<='Z') || rt=='.')return rt;
}
}
void deleteone(int x, int y, int z)
{
int a;
for(a=1;!islive[x+a][y][z];a++);
view[x+a][y][z][5] = view[x][y][z][5];
for(a=1;!islive[x-a][y][z];a++);
view[x-a][y][z][6] = view[x][y][z][6];
for(a=1;!islive[x][y+a][z];a++);
view[x][y+a][z][2] = view[x][y][z][2];
for(a=1;!islive[x][y-a][z];a++);
view[x][y-a][z][4] = view[x][y][z][4];
for(a=1;!islive[x][y][z+a];a++);
view[x][y][z+a][3] = view[x][y][z][3];
for(a=1;!islive[x][y][z-a];a++);
view[x][y][z-a][1] = view[x][y][z][1];
islive[x][y][z] = false;
}
bool check(int x, int y, int z)
{
char color='a';
FOR(k,6)
{
if(view[x][y][z][k]=='.')return false;
if(view[x][y][z][k]=='a')continue;
if(view[x][y][z][k]==color || color=='a')
{
color = view[x][y][z][k];
}else{
return false;
}
}
return true;
}
bool work()
{
bool rt = false;
FOR(x,n) FOR(y,n) FOR(z,n)
if(islive[x][y][z] && !check(x,y,z))
{
deleteone(x,y,z);
rt = true;
}
return rt;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==0)break;
FOR(x,n)FOR(y,n)FOR(z,n)FOR(k,6)view[x][y][z][k] = 'a';
memset(islive,1,sizeof islive);
FOR(x,n)
{
}

while(work());
int ans = 0;
FOR(i,n) FOR(j,n) FOR(k,n)
if(islive[i][j][k]) ans++;
printf("Maximum weight: %d gram(s)\n",ans);
}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：24765次
• 积分：950
• 等级：
• 排名：千里之外
• 原创：76篇
• 转载：0篇
• 译文：0篇
• 评论：0条
评论排行