uva 253 - Cube painting

来源:互联网 发布:sql update多个匹配 编辑:程序博客网 时间:2024/04/20 00:21


 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 of these colors. The cube's faces are numbered as in Figure 1.

picture21

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 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 ab, r, or g. The tex2html_wrap_inline128 character (tex2html_wrap_inline130 ) from the left gives the color of facei. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds torggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138tex2html_wrap140

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 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.)

Output

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.

Sample Input

rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg

Sample Output

TRUEFALSEFALSE

要注意涂色的顺序是按题目中给的

上前左右后下

 1  2  3  4  5  6
 1  4  2  5  3  6
 1  5  4  3  2  6
 1  3  5  2  4  6
 6  2  4  3  5  1
 ...
 2  3  1  6  4  5
 ...
 5  4  1  6  3  2
 ....
 3  2  6  1  5  4
 ...
 4  2  1  6  5  3
 up   1
down 6
a    2
b    3
c    4
d    5

up dwon 有六种组合其对应的abcd有四种共24种,

 以上下为轴,左右为轴,前后为轴
每个8种,上下可以翻转。
其余四个面顺时针旋转:
前-》左
左-》后
后-》右
右-》前3    4   5   6

没有想到简单的表示方法只能手打穷举了......哭

#include <stdio.h>
#include <string.h>
char s[12];
int sort(char up,char down,char a,char b,char c,char d)
{if ((up==s[6])&&(down==s[11])&&(a==s[7])&&(b==s[8])&&(c==s[9])&&(d==s[10])) return 1;
 if ((up==s[6])&&(down==s[11])&&(c==s[7])&&(a==s[8])&&(d==s[9])&&(b==s[10])) return 1;
 if ((up==s[6])&&(down==s[11])&&(d==s[7])&&(c==s[8])&&(b==s[9])&&(a==s[10])) return 1;
 if ((up==s[6])&&(down==s[11])&&(b==s[7])&&(d==s[8])&&(a==s[9])&&(c==s[10])) return 1;
 return 0;
};
void main()
{int f1,f2,f3,f4,f5,f6;
 while (scanf("%s",&s)!=EOF)
 {f1=sort(s[0],s[5],s[1],s[2],s[3],s[4]);
  f2=sort(s[1],s[4],s[2],s[0],s[5],s[3]);
  f3=sort(s[2],s[3],s[1],s[5],s[0],s[4]);
  f4=sort(s[5],s[0],s[1],s[3],s[2],s[4]);
  f5=sort(s[4],s[1],s[3],s[0],s[5],s[2]);
  f6=sort(s[3],s[2],s[1],s[0],s[5],s[4]);
  if (f1+f2+f3+f4+f5+f6) printf("TRUE\n");
  else printf("FALSE\n");
 }
}

原创粉丝点击