UVA 253 Cube painting

来源:互联网 发布:手机怎么注册淘宝会员 编辑:程序博客网 时间:2024/04/23 15:38

 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 a br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) 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 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138 tex2html_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
做出模型,进行穷举!
代码如下:
#include <stdio.h>#include <string.h>int rot[30][10]=   {      {1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6},      {2,6,3,4,1,5},{2,3,1,6,4,5},{2,1,4,3,6,5},{2,4,6,1,3,5},      {3,2,6,1,5,4},{3,1,2,5,6,4},{3,5,1,6,2,4},{3,6,5,2,1,4},      {6,5,3,4,2,1},{6,4,5,2,3,1},{6,3,2,5,4,1},{6,2,4,3,5,1},      {5,1,3,4,6,2},{5,4,1,6,3,2},{5,6,4,3,1,2},{5,3,6,1,4,2},      {4,5,6,1,2,3},{4,6,2,5,1,3},{4,2,1,6,5,3},{4,1,5,2,6,3}   };char str2[10];int main(void){    char str1[10]={'\0'};    int i;    char str[12];    int turn(char *s);    while(scanf("%s",str)!=EOF)    {     for(i=0;i<6;i++)     {       str1[i]=str[i];      str2[i]=str[6+i];     }     str1[i]='\0';     if(turn(str1))      printf("TRUE\n");     else printf("FALSE\n");     }    return 0;} int turn(char *s){    int i,j;    char a[30][10]={'\0'};        for(i=0;i<24;i++)    {      for(j=0;j<6;j++)       a[i][j]=s[rot[i][j]-1];     if(!strcmp(str2,a[i]))      return 1;    }    return 0;}


原创粉丝点击