标签:
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
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 of these colors. The cube‘s faces are numbered as 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, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r, or g. The character ( ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90 , the one changes into the other.
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 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)
The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.
rbgggrrggbgr rrrbbbrrbbbr rbgrbgrrrrrg
TRUE FALSE FALSE
就是固定向上和下面不变,旋转其余四个面,每次改变向上的面,就会枚举所有6*4个不同的姿态,再与第二个骰子比较,要点空间想象力,不行拿个称手的东西比划下就出来了,还有旋转时注意下姿态。
#include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; //列出不同面朝上是各个位置的数字 int dir[6][6] = { { 0, 1, 2, 3, 4, 5 }, { 1, 0, 3, 2, 5, 4 }, { 2, 0, 1, 4, 5, 3 }, { 3, 0, 4, 1, 5, 2 }, { 4, 0, 2, 3, 5, 1 }, { 5, 1, 3, 2, 4, 0 } }; char a[10]; char b[10]; char s[20]; bool judge() { for (int i = 0; i < 6; i++) { char temp[10] = ""; for (int j = 0; j < 6; j++) //置骰子姿态分别为各个不同数字向上 temp[j] = a[dir[i][j]]; for (int j = 0; j < 4; j++) { char c_temp; c_temp = temp[1]; //旋转,注意yy出旋转是数字变化的方式 temp[1] = temp[2]; temp[2] = temp[4]; temp[4] = temp[3]; temp[3] = c_temp; if (strcmp(temp, b) == 0) return true; } } return false; } int main() { while (scanf("%s", s) != EOF) { for (int i = 0; i < 6; i++) a[i] = s[i]; a[6] = 0; for (int i = 0; i < 6; i++) b[i] = s[i + 6]; b[6] = 0; if (judge()) cout << "TRUE" << endl; else cout << "FALSE" << endl; } }
标签:
原文地址:http://blog.csdn.net/qq_18738333/article/details/44968341