Uva LV 2995 Image Is Everything 模拟,坐标映射,视图映射 难度: 1

题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996


题意

被射击掉了一些列的魔方。组成模仿的每个方块的六个面颜色相同。给六个面的视图,求魔方最多还剩下多少个小块。

魔方最多十阶。

思路

关键在于将视图的坐标(加上视图深度)映射为三维坐标系内的坐标,之后就可以不断删除会造成矛盾的暴露在表面的方块,直到没有方块或者没有矛盾为止。

感想

1. 注意<写成了>=

2. 忘记了检测当前方块是否已经删除过了。

3. 忘了memset

4. 视图的映射有价值,不过需要注意坐标系建立不同

代码

Runtime: 0.006

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <cassert>

using namespace std;
#define LOCAL_DEBUG
const int MAXN = 11;

int n;
bool del[MAXN][MAXN][MAXN];
char color[MAXN][MAXN][MAXN];
char fc[6][MAXN][MAXN];
int deep[6][MAXN][MAXN];
int facec[3];
int polarc[3];

char statusDescribe[6][4] = {
    "YXZ",
    "ZXy",
    "yXz",
    "zXY",
    "YZx",
    "YzX"
};


int getAns() {
    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 (!del[i][j][k])ans++;
            }
        }
    }
    return ans;
}


void face2polar(int fid, int facec[3], int polarc[3]) {
    for (int i = 0; i < 3; i++) {
        char sta = statusDescribe[fid][i];
        if (sta >= 'X' && sta <= 'Z') {
            polarc[i] = facec[sta - 'X'];
        }
        else {
            polarc[i] = n - 1 - facec[sta - 'x'];
        }
    }
}


void polar2face(int fid, int facec[3], int polarc[3]) {
    for (int i = 0; i < 3; i++) {
        char sta = statusDescribe[fid][i];
        if (sta >= 'X' && sta <= 'Z') {
            facec[sta - 'X'] = polarc[i];
        }
        else {
            facec[sta - 'x'] = n - 1 - polarc[i];
        }
    }
}



int main() {
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output2.txt", "w", stdout);
#endif // LOCAL_DEBUG
    for (int ti = 1; scanf("%d", &n) == 1 && n; ti++) {
        memset(del, 0, sizeof(del));
        memset(color, 0, sizeof(color));
        memset(fc, 0, sizeof(fc));
        memset(deep, 0, sizeof(deep));
        memset(facec, 0, sizeof(facec));
        memset(polarc, 0, sizeof(polarc));
        char buff[100];
        cin.getline(buff, 100);
        for(int i = 0; i < n;i++){
            cin.getline(buff, 100);
            for (int k = 0; k < 6; k++) {
                for (int j = 0; j < n; j++) {
                    fc[k][i][j] = buff[(n + 1) * k + j];
                }
            }
        }
        
        int &x = facec[0];
        int &y = facec[1];
        int &z = facec[2];
        int &a = polarc[0];
        int &b = polarc[1];
        int &c = polarc[2];
        for (int fid = 0; fid < 6; fid++) {
            for (x = 0; x < n; x++) {
                for (y = 0; y < n; y++) {
                    if (fc[fid][x][y] == '.') {
                        deep[fid][x][y] = n;
                        for (z = 0; z < n; z++) {
                            face2polar(fid, facec, polarc);
                        //    printf("R: %d, del %d-(%d, %d, %d) : (%d, %d, %d)
", getAns(), fid, x, y, z, a, b, c);
                            del[a][b][c] = true;
                        }
                    }
                }
            }
        }
        bool checkFlag = true;
        while (checkFlag) {
            checkFlag = false;
            for (int fid = 0; fid < 6; fid++) {
                for (x = 0; x < n; x++) {
                    for (y = 0; y < n; y++) {
                        for (z = deep[fid][x][y]; z < n; z++, deep[fid][x][y]++) {
                            face2polar(fid, facec, polarc);
                            if (del[a][b][c])continue;
                            else if (color[a][b][c] == 0 || color[a][b][c] == fc[fid][x][y]) {
                                color[a][b][c] = fc[fid][x][y];
                                break;
                            }
                            else{
                                del[a][b][c] = true;
                                checkFlag = true;
                            }
                        }
                    }
                }
            }
        }
        int ans = getAns();
        printf("Maximum weight: %d gram(s)
", ans);
    }

    return 0;
}
View Code
原文地址:https://www.cnblogs.com/xuesu/p/10357074.html