Let's talk about it: as soon as we see the color of the cube, we start to have a little fear. After all, the dyeing problem in high school mathematics is never simple. This question is to dye the six sides of the cube and then determine whether the two colored cubes are the same. In fact, think twice, the cube is nothing more than three sides, if you start to determine the two sides. As shown in figure 1 below: assume that the four sides 1, 2, 6, and 5 are determined first (this is the only case), and then put 3, 4. There are only two cases. But these two situations are different. This may be the reflection of the question. The idea at the beginning was to find the three sides and then compare them to determine whether they are equal, but I really couldn't figure out how to exclude reflection. Therefore, you can only use the second method. Design a data structure that contains the number of the opposite side of a plane, and an array that stores the numbers of the other four sides in sequence from this area. At last, you just need to fix the cube and try to take the surface of cube two as the bottom surface, then judge the opposite side, and whether the remaining four sides can be completely equal by rotation!
Question:
Cube painting
We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one
We have a tool for cube dyeing. It provides three different colors: blue, red, and green. Each side of the cube is colored.
These colors. The Cube's faces are numbered as in Figure 1.
The plane number of the cube is shown in Figure 1.
Figure 1.
Since a cube has 6 faces, our machine can paint a face-numbered cube in different ways. When ignoring the face-numbers,
Because a cube has six faces, our machine has a total dyeing solution for the number of cubes. When the number of the face is ignored,
Number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string
The dyeing scheme is much less, because cubes can be flipped. See the following example. We use a 6-character string to indicate a colored
6 characters, where each character isB,R, OrG. The character () from the Left gives the color of faceI. For example,
Cube. Each character can only be B, R, or G. from the left, the I character (1 <= I <= 6) indicates the I.
Figure 2 is a pictureRbgggrAnd Figure 3 correspondsRggbgr. Notice that both cubes are painted in the same way: by rotating it
For example, Figure 2 can be represented by rbgggr. Figure 3 corresponds to rggbgr. Note that the two cubes are colored in the same way: place one of them along the axis
Around the vertical axis by 90, the one changes into the other.
If you rotate 90 degrees horizontally, it becomes another one.
Input
The input of your program is a textfile that ends with the standard end-of-File marker. Each line is a string of 12 characters. The first 6
The input is a text file ended with EOF. Each line contains 12 characters. The first six characters represent the colored cubes, and the remaining six characters represent
Characters of this string are the representation of a painted cube, the remaining 6 Characters give you the representation of another
Another colored cube.
Cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations
Your program will determine whether the two cubes are colored in the same way, that is, whether one can be converted to another by rotating.
One can be turned into the other. (reflections are not allowed .)
(Images are not allowed)
Output
The output is a file of Boolean. For each line of input, output containsTrueIf the second half can be obtained from the first half
The output is a file consisting of a Boolean number. True is output. If the second colored cube can be converted to the first by rotation, otherwise false is output.
Rotation as describes abve,FalseOtherwise.
Sample Input
rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg
Sample output
TRUEFALSEFALSE
Source code:
# Include <stdio. h> typedef struct describe {// int top when a surface is the bottom surface; // int around [4], opposite of the bottom surface, the remaining four sides are arranged in a counter-clockwise manner} des; des cube [6]; char C [13], c1 [7], C2 [7]; void Init (); // initialize the information of each plane void get_des (); // break down the representationint judge (INT) of each plane from the string; // judge whether the two cubes are the same int main () {int I, j, K, flag; Init (); // freopen ("data.txt", "r", stdin); While (~ Scanf ("% s", c) {get_des (C, C1, C2); flag = 0; for (I = 0; I <6; I ++) if (c2 [I] = c1 [0]) // if the two sides of the cube have the same color as the two sides of the cube, if (Judge (I )) {printf ("True \ n"); flag = 1; break;} If (! Flag) printf ("false \ n");} return 0;} void get_des () {int I, j; for (I = 0; I <6; I ++) c1 [I] = C [I]; for (I = 6, j = 0; I <12; I ++, J ++) c2 [J] = C [I];} void Init () {// For convenience, subtract the sequence numbers in the question from the Cube [0]. top = 5; cube [0]. around [0] = 1, cube [0]. around [1] = 3, cube [0]. around [2] = 4, cube [0]. around [3] = 2; cube [5]. top = 0; cube [5]. around [0] = 1, cube [5]. around [1] = 2, cube [5]. around [2] = 4, cube [5]. around [3] = 3; cube [1]. top = 4; cube [1]. around [0] = 2, cube [1]. aroun D [1] = 5, cube [1]. around [2] = 3, cube [1]. around [3] = 0; cube [4]. top = 1; cube [4]. around [0] = 2, cube [4]. around [1] = 0, cube [4]. around [2] = 3, cube [4]. around [3] = 5; cube [2]. top = 3; cube [2]. around [0] = 1, cube [2]. around [1] = 0, cube [2]. around [2] = 4, cube [2]. around [3] = 5; cube [3]. top = 2; cube [3]. around [0] = 1, cube [3]. around [1] = 5, cube [3]. around [2] = 4, cube [3]. around [3] = 0;} int judge (INT face) {int I, j, k; If (c1 [cube [0]. top]! = C2 [cube [face]. top]) return 0; for (I = 0; I <4; I ++) {// fixed cube 1, Rotated Cube 2, and determined whether there is a matching condition K = 0; for (j = 0; j <4; j ++) if (c2 [cube [face]. around [(I + J) % 4]! = C1 [cube [0]. Around [J]) {k = 1; break;} If (! K) return 1;} return 0 ;}