首页 > 代码库 > LA2995 Image Is Everything

LA2995 Image Is Everything

很有助于思考的模拟题

 

#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <algorithm>using namespace std;const int maxn = 15;const int maxv = 1005;const int mod = 1e9+7;const int INF = 0x3f3f3f3f;typedef long long LL;char s[7][maxn][maxn];char pos[maxn][maxn][maxn];int n;void get_pos(int k,int i,int j,int d,int &x,int &y,int &z){    if(k==0){x = j;y = n-d-1;z = n-i-1;}    if(k==1){x = d;y = j;z = n-i-1;}    if(k==2){x = n-j-1;y = d;z = n-i-1;}    if(k==3){x = n-d-1;y = n-j-1;z = n-i-1;}    if(k==4){x = j;y = i;z = n-d-1;}    if(k==5){x = j;y = n-i-1;z = d;}}int main(){//    freopen("in.txt","r",stdin);//    freopen("out.txt","w",stdout);    while(~scanf("%d",&n) && n)    {        for(int i = 0;i<n;++i)            for(int j = 0;j<6;++j)                scanf("%s",s[j][i]);        for(int i = 0;i<n;++i)            for(int j = 0;j<n;++j)                for(int k = 0;k<n;++k)                    pos[i][j][k] = #;        for(int k = 0;k<6;++k)            for(int i = 0;i<n;++i)                for(int j = 0;j<n;++j)if(s[k][i][j]==.)                {                    for(int l = 0;l<n;++l)                    {                        int x,y,z;                        get_pos(k,i,j,l,x,y,z);                        pos[x][y][z] = .;                    }                }        while(1)        {            int ok = 1;            for(int k = 0;k<6;++k)                for(int i = 0;i<n;++i)                    for(int j = 0;j<n;++j)                        for(int l = 0;l<n;++l)                        {                            int x,y,z;                            get_pos(k,i,j,l,x,y,z);                            if(pos[x][y][z]==.)continue;                            if(pos[x][y][z]==#){pos[x][y][z] = s[k][i][j];break;}                            if(pos[x][y][z]==s[k][i][j])break;                            pos[x][y][z] = .;                            ok = 0;                        }            if(ok)break;        }        int ans = 0;        for(int i = 0;i<n;++i)            for(int j = 0;j<n;++j)                for(int k = 0;k<n;++k)                    if(pos[i][j][k]!=.)ans++;        printf("Maximum weight: %d gram(s)\n",ans);    }    return 0;}

 

LA2995 Image Is Everything