UVa OJ 1030

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
const int maxn=10;
int n;
char pos[maxn][maxn][maxn];
char view[6][maxn][maxn];
char read_char()
{
    char ch;
    for(;;)
    {
        ch=getchar();
        if((ch>='A'&&ch<='Z')||ch=='.') return ch;
    }
}
void get(int k,int i,int j,int len,int &x,int &y,int &z)
{
    if(k==0){x=len;y=j;z=i;}
    if(k==1){x=n-1-j;y=len;z=i;}
    if(k==2){x=n-1-len;y=n-1-j;z=i;}
    if(k==3){x=j;y=n-1-len;z=i;}
    if(k==4){x=n-1-i;y=j;z=len;}
    if(k==5){x=i;y=j;z=n-1-len;}
}
int main()
{
    //freopen("a.txt","r",stdin);
    while(scanf("%d",&n)==1&&n)
    {
        REP(i,n)REP(k,6)REP(j,n) view[k][i][j]=read_char();
        REP(i,n)REP(j,n)REP(k,n) pos[i][j][k]='#';
        REP(k,6) REP(i,n) REP(j,n)
           if(view[k][i][j]=='.')
             REP(p,n)
             {
                 int x,y,z;
                 get(k,i,j,p,x,y,z);
                 pos[x][y][z]='.';
             }
        for(;;)
        {
            bool done=true;
            REP(k,6)REP(i,n)REP(j,n)
              if(view[k][i][j]!='.')
                 REP(p,n)
                 {
                     int x,y,z;
                     get(k,i,j,p,x,y,z);
                     if(pos[x][y][z]=='.')continue;
                     if(pos[x][y][z]=='#')
                     {
                         pos[x][y][z]=view[k][i][j];
                         break;
                     }
                     if(pos[x][y][z]==view[k][i][j])break;
                     pos[x][y][z]='.';
                     done=false;
                 }
                 if(done)break;
        }
        int ans=0;
        REP(i,n)REP(j,n)REP(k,n)
        if(pos[i][j][k]!='.')ans++;
        printf("Maximum weight: %d gram(s)\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值