Roughly test instructions: There are three colors, a cube 6 faces can be painted a color. Now give two cubes with each face painted in color to determine whether the two cubes are equal by rotation.
The rotation of the cube has a lot of results, the first can be 0,1,2,3,4,5 (the order is: up and down) on either side of the top, and then the vertical four faces can be facing forward.
For example: 0 is up (then must be 5), then the following results can be obtained after rotation:
Forward and left
0 1 2 3 4 5
0 2 4 1 3 5
0 4 3 1 2 5
0 3 1 4 2 5
A total of 4 cases. Six faces also 4*6=24 the situation. Due to the small value, pre-treatment can be done beforehand.
When judging whether the two cubes are equal, only rotating the second cube is enough.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intMain () {//freopen ("In.txt", "R", stdin); intway[6][4][5]= {1,2,3,4,5,2,4,1,3,5,4,3,2,1,5,3,1,4,2,5,0,3,2,5,4,3,5,0,2,4,5,2,3,0,4,2,0,5,3,4,0,1,4,5,3,1,5,0,4,3,5,4,1,0,3,4,0,5,1,3,0,4,1,5,2,4,5,0,1,2,5,1,4,0,2,1,0,5,4,2,0,2,5,3,1,2,5,0,3,1,5,3,2,0,1,3,0,5,2,1,1,3,2,4,0,3,4,1,2,0,4,2,3,1,0,2,1,4,3,0}; //pre-processing, all situations are directly typed. /*for (int i=0;i<6;i++)//output all conditions {for (int j=0;j<4;j++) {printf ("%d", I); for (int k=0;k<5;k++) printf ("%d", way[i][j][k]); printf ("\ n"); } }*/ Chars[ -]; while(~SCANF ("%s", s)) { BOOLFlag; for(intj=6; j< A; J + +) {flag=false; if(s[j]==s[0])//determine if the first color is equal, not equal to skip directly for(intk=0; k<4; k++) { for(intm=0; m<5; m++) { if(s[way[0][0][m]]!=s[way[j-6][k][m]+6]) Break; if(m==4) Flag=true; } if(flag) Break; } if(flag) Break; } if(flag) printf ("true\n"); Elseprintf ("false\n"); } return 0;}
UVA 253 Cube painting