uva 253 - Cube painting 思维问题

来源:互联网 发布:卫星机顶盒改网络电视 编辑:程序博客网 时间:2022/01/21 22:17

253 - 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 tput

TRUEFALSEFALSE


uva 253 思维问题:

这道问题开始觉得好复杂~~要列举的情况有好多种~~~

其实仔细想想思路还是蛮清晰的

最后总结出来对于一种开始已经摆好位置的方块 总过包含则24种变换(包含自己本身)

首先确定上和下的位置

然后在确定周围图形的顺序

上下位置的确定有3种周围的顺序有4种

例如16为上下底则会有4中情况

{1,2,4,5,3,6},{1,3,2,4,5,6},{1,5,3,2,4,6},{1,4,5,3,2,6},

25为上下底也有4中情况

{2,6,4,1,3,5},{2,3,6,4,1,5},{2,1,3,6,4,5},{2,4,1,3,6,5},

43为上下底也有4种情况

{4,6,5,1,2,3},{4,2,6,5,1,3},{4,1,2,6,5,3},{4,5,1,2,6,3}};

然后61的情况和16的顺序相反

52,34,分别和25,43相反

然后的到结果

下面是代码



#include<stdio.h>#include<string.h>int a[15][9]={{},{1,2,4,5,3,6},{1,3,2,4,5,6},{1,5,3,2,4,6},{1,4,5,3,2,6},{2,6,4,1,3,5},{2,3,6,4,1,5},{2,1,3,6,4,5},{2,4,1,3,6,5},{4,6,5,1,2,3},{4,2,6,5,1,3},{4,1,2,6,5,3},{4,5,1,2,6,3}}; //确定12种情况 然后结论相反char  ans[26][8];char  sample[20];char  input[10],output[10],converse[10];void inout()   {    int i,j;    for( i=0;i<6;i++){       input[i]=sample[i];       }             input[i]='\0';    for( j=0;j<6;j++,i++){       output[j]=sample[i];       }       output[j]='\0';  //       printf("%s %s\n",input,output);   }void changeform(){   int i,j,k;   for(i=1;i<=12;i++){      for(j=0;j<6;j++)          ans[i][j]=input[ a[i][j]-1 ];                      ans[i][j]='\0';   }       //   for(i=1;i<=12;i++)//      printf("%s\n",ans[i]);}void conver(){    char temp2,temp4,temp3;    temp2=output[2];    temp4=output[4];    temp3=output[3];    output[4]=temp2;    output[2]=temp3;    output[3]=temp4;    int i,j;    for( i=5,j=0;j<6;j++,i--)       converse[j]=output[i];         converse[j]='\0';//    printf("%s\n",converse);    }int  check(){   int i,j,flag=0;        for(i=1;i<=12;i++)   {     if( strcmp(ans[i],output)==0 ){flag=1;break;}                       if( strcmp(ans[i],converse)==0 ){flag=1;break;}                   }     return flag;}int main(){    while (scanf("%s",sample)!=EOF){    inout();   //从输入数据中提取两个正方体颜色的排列    changeform();  //枚举出所有的12种情况      conver();  //改变数据的格式    if(check()==1)printf("TRUE\n") ;//验证数据结论    else printf("FALSE\n");    }}













原创粉丝点击