LA 2995 Image Is Everything

题目

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26450

题解

其实这道题只要看了题解就好简单的样子,注意学习他的化简代码的神奇能力和分析问题化简为繁的神奇能力

代码

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
const int maxn=10+5;
const int maxm=10;

char mx[maxm][maxn][maxn],cell[maxn][maxn][maxn];
int n;

inline char input()
{
    char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    return ch;
}

inline void get(int k,int i,int j,int dep,int &x,int &y,int &z)
{
    if(k==1) {x=i;  y=j;      z=dep;    return ;}
    if(k==2) {x=i;  y=dep;    z=n+1-j;  return ;}
    if(k==3) {x=i;  y=n+1-j;  z=n+1-dep;return ;}
    if(k==4) {x=i;  y=n+1-dep;z=j;    return ;}
    if(k==5) {x=dep;y=j;      z=n+1-i;  return ;}
    x=n+1-dep;y=j;z=i;
}

int x,y,z;
inline void solve()
{
    rep(X,1,n) rep(Y,1,n) rep(Z,1,n) cell[X][Y][Z]='#';
    rep(i,1,n) rep(k,1,6) rep(j,1,n)
    {
        mx[k][i][j]=input();
        if(mx[k][i][j]=='.')
            rep(dep,1,n)
            {
                get(k,i,j,dep,x,y,z);   
                cell[x][y][z]='.';
            }
    }
    int done=1;
    while(done)
    {
        done=0;
        rep(k,1,6) rep(i,1,n) rep(j,1,n) if(mx[k][i][j]!='.')
            rep(dep,1,n)
            {
                get(k,i,j,dep,x,y,z);
                char &Cell=cell[x][y][z];
                if(Cell=='.') continue;
                if(Cell=='#')
                {
                    Cell=mx[k][i][j];break;
                }
                if(Cell==mx[k][i][j]) break;
                Cell='.';
                done=1;
            }
    }
    int ans=0;
    rep(X,1,n) rep(Y,1,n) rep(Z,1,n) 
        if(cell[X][Y][Z]!='.') ans++;
    printf("Maximum weight: %d gram(s)\n",ans);
    return ;
}

inline void debug()
{
    int k,i,j,dep;
    scanf("%d%d%d%d%d",&n,&k,&i,&j,&dep);
    get(k,i,j,dep,x,y,z);
    printf("x=%d y=%d z=%d",x,y,z);
    return ;
}

int main()
{
    while(scanf("%d",&n)==1&&n) solve();
//  debug();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值