LA 2995 Image Is Everything

来源:互联网 发布:网络推广月度工作计划 编辑:程序博客网 时间:2024/05/24 05:51

题目

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
原创粉丝点击