LA 2995 & ZOJ2714 Image is Everything

来源:互联网 发布:arora浏览器 windows 编辑:程序博客网 时间:2024/05/17 00:51
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.2ZZ ZZ ZZ ZZ ZZ ZZZZ ZZ ZZ ZZ ZZ ZZ0

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 read_char(){    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)        {             FOR(y,n) view[x][y][1][3] = read_char();             FORDAO(z,n) view[x][1][z][2] = read_char();             FORDAO(y,n) view[x][y][n][1] = read_char();             FOR(z,n) view[x][n][z][4] = read_char();             FOR(y,n) view[1][y][n-x+1][5] = read_char();             FOR(y,n) view[n][y][x][6] = read_char();         }                 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