UVALive 2995 Image Is Everything——模拟

版权声明:欢迎大家转载,转载请注明出处 https://blog.csdn.net/hao_zong_yin/article/details/82110324

建立视图和矩阵之间的对应关系,然后模拟

#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 = 15;
int n;
char pos[maxn][maxn][maxn];
char view[6][maxn][maxn];
inline void input(char &c) {
    do { c = getchar(); } while (c != '.' && (c < 'A' || c > 'Z'));
}
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; }
    else if (k == 1) { x = n - 1 - j; y = len; z = i; }
    else if (k == 2) { x = n - 1 - len; y = n - 1 - j; z = i; }
    else if (k == 3) { x = j; y = n - 1 - len; z = i; }
    else if (k == 4) { x = n - 1 - i; y = j; z = len; }
    else if (k == 5) { x = i; y = j; z = n - 1 - len; }
}
void solve() {
    rep(i, 0, n) rep(k, 0, 6) rep(j, 0, n) input(view[k][i][j]);
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) pos[i][j][k] = '#';
    rep(k, 0, 6) rep(i, 0, n) rep(j, 0, n) if (view[k][i][j] == '.') rep(p, 0, n) {
        int x, y, z; get(k, i, j, p, x, y, z);
        pos[x][y][z] = '.';
    }
    while (1) {
        bool done = true;
        rep(k, 0, 6) rep(i, 0, n) rep(j, 0, n) if (view[k][i][j] != '.') rep(p, 0, 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, 0, n) rep(j, 0, n) rep(k, 0, n) if (pos[i][j][k] != '.') ans++;
    printf("Maximum weight: %d gram(s)\n", ans);
}
int main() {
    while (~scanf("%d", &n) && n) solve();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hao_zong_yin/article/details/82110324