Uva--253 (数学,枚举)

2014-06-07 18:43:40

题意&思路:给出两个cube,每个面涂上颜色,判断这两个cube是否相同(即能否通过旋转获得一样的视觉效果)。直接枚举第二个cube,分别让它的三条轴位于竖直位置,旋转一圈,逐一判断(注意:轴是有方向的,需要上下颠倒一次进行第二次考虑,这里取而代之地把cube一倒置一次,以缩小思考量)

#include <cstdio>
#include <iostream>
using namespace std;

char s[20],c1[10],c2[10];

bool Judge(int a,int b,int c,int d,int e,int f){
    if(c1[1] == c2[a] && c1[2] == c2[b] && c1[3] == c2[c] &&
            c1[4] == c2[d] && c1[5] == c2[e] && c1[6] == c2[f])
        return true;
    return false;
}

void Swap(char & a,char & b){
    char temp;
    temp = a;
    a = b;
    b = temp;
}

int main(){
    int p[12][6] = {{1,2,3,4,5,6},{1,3,5,2,4,6},{1,5,4,3,2,6},{1,4,2,5,3,6},
        {3,1,2,5,6,4},{3,2,6,1,5,4},{3,6,5,2,1,4},{3,5,1,6,2,4},
        {5,4,1,6,3,2},{5,1,3,4,6,2},{5,3,6,1,4,2},{5,6,4,3,1,2}};
    while(scanf("%s",s + 1) == 1){
        for(int i = 1; i <= 6; ++i){
            c1[i] = s[i];
        }
        for(int i = 7; i <= 12; ++i){
            c2[i - 6] = s[i];
        }
        int flag = 0;
        for(int i = 0; i < 12; ++i){
            if(Judge(p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5])){
                flag = 1;
                break;
            }
        }
        if(!flag){
            Swap(c1[1],c1[6]);
            Swap(c1[3],c1[4]);
            for(int i = 0; i < 12; ++i){
                if(Judge(p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5])){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag)
            puts("TRUE");
        else
            puts("FALSE");
    }
    return 0;
}

 

posted @ 2014-06-07 18:47  Naturain  阅读(219)  评论(0编辑  收藏  举报