Uva 253 Cube painting

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=189

picture21

固定一个面,然后只有一个旋转轴:6*4 = 24种情况

1.  固定1 2 6 5,共有:4*4 = 16中情况

2.  固定3 4,有2*4 = 8种情况

因为分了两种情况,所以要注意旋转的方向。

特别要注意不同情况不要相交:判断每种情况前要初始化。

WA了6次,无比纠结。

// 20:14
# include <stdio.h>

char buffer[15];

char x[10];

int r[][4] = {{0,1,5,4}, {2,1,3,4}};
const int t[][2] = {{0,0},{1,0},{2,0},{3,0},{3,1},{1,1}};

void init(void)
{
    for (int i = 0; i < 6; ++i) x[i] = buffer[6+i];
}

void rotate(char *s, int n, int k)
{
    for (int i = 0; i < n; ++i) {
        int ch = s[r[k][0]];
        for (int j = 0; j < 3; ++j) s[r[k][j]] = s[r[k][j+1]];
        s[r[k][3]] = ch;
    }
}
bool check(char *s)
{
    for (int i = 0; i < 6; ++i) {
        if (s[i] != buffer[i]) return false;
    }
    return true;
}

bool test(void)
{
    for (int i = 0; i < 4; ++i) {
        init();
        rotate(x, i, 0);
        for (int j = 0; j < 4; ++j) {
            rotate(x, 1, 1);
            if (check(x)) return true;
        }
    }
    init();
    rotate(x, 1, 1); rotate(x, 1, 0);
    for (int i = 0; i < 4; ++i) {
        rotate(x, 1, 1);
        if (check(x)) return true;
    }
    init();
    rotate(x, 3, 1); rotate(x, 1, 0);
    for (int i = 0; i < 4; ++i) {
        rotate(x, 1, 1);
        if (check(x)) return true;
    }
    return false;
}

int main()
{
    while (scanf("%s", buffer) != EOF) {
        if (test()) puts("TRUE");
        else puts("FALSE");
    }
    
    return 0;
}
原文地址:https://www.cnblogs.com/txd0u/p/3395201.html