这道题要我们判断对于一个立方体用三种颜色染色(可以只使用其中的一种或两种颜色),题目所给的两种染色方案本质上是否相同(即立方体经过翻转后可重合)。
对于这道题,我们只要枚举出第一种染色方案下的立方体所有能够通过翻转产生的其他本质相同的染色方案,与第二种方案比较就可以得到结果。
即枚举立方体绕X,Y,Z轴旋转后的结果(三个轴均可以绕着旋转0度,90度,180度,270度),最多4^3=64中情况。
我的解题代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <string> #include <algorithm> using namespace std; const int X_rotate[4][6] = { 1, 2, 3, 4, 5, 6, 3, 2, 6, 1, 5, 4, 6, 2, 4, 3, 5, 1, 4, 2, 1, 6, 5, 3 }; const int Y_rotate[4][6] = { 1, 2, 3, 4, 5, 6, 5, 1, 3, 4, 6, 2, 6, 5, 3, 4, 2, 1, 2, 6, 3, 4, 1, 5 }; const int Z_rotate[4][6] = { 1, 2, 3, 4, 5, 6, 1, 4, 2, 5, 3, 6, 1, 5, 4, 3, 2, 6, 1, 3, 5, 2, 4, 6 }; char s[16],s1[8],s2[8],s3[8]; int main() { while(cin >> s) { int ok=0; for(int i=0; i<4; i++) if(!ok) { for(int t=0; t<6; t++) s1[t]=s[X_rotate[i][t]-1]; for(int j=0; j<4; j++) if(!ok) { for(int t=0; t<6; t++) s2[t]=s1[Y_rotate[j][t]-1]; for(int k=0; k<4; k++) if(!ok) { for(int t=0; t<6; t++) s3[t]=s2[Z_rotate[k][t]-1]; int ok2=1; for(int t=0; t<6; t++) if(s3[t]!=s[t+6]){ ok2=0; break;} if(ok2) ok=1; } } } if(ok) cout << "TRUE\n"; else cout << "FALSE\n"; } return 0; }