hdu 5292 Pocket Cube

来源:互联网 发布:鲁滨逊漂流记java游戏 编辑:程序博客网 时间:2024/05/01 18:56

                                                                    Pocket Cube

                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                   Total Submission(s): 92    Accepted Submission(s): 48

Problem Description
Pocket Cube is the 2×2×2 equivalent of a Rubik’s Cube(3×3×3). The cube consists of 8 pieces, all corners. (from wiki)

It was a Pocket Cube. Unfortunately, the Cube fell to the ground and broke. It took you some time to explore the construction of the Cube. Then you assembled the Pocket Cube. Unfortunately, you didn’t assembled it in the right way. So here is the question. You want to know whether it can return to the right position.

The right position means four blocks in each face has the same color. You can only rotate the Cube to return it to the right position.

A Cube is given in its layout.


The right position rotates in red face clockwisely.
You can get more details from input case.
w represents white , y represents yellow , o represents orange , r represents red , g represents green , b represents blue. In the right position, white and yellow , orange and red , green and blue are in the opposite face.
 

Input
The first line of input contains only one integer T(<=10000), the number of test cases.
Each case contains a Pocket Cube described above. After each case , there is a blacnk line. It guarantees that the corners of the Cube is right.
 

Output
Each case contains only one line. Each line should start with “Case #i: ”,with i implying the case number, followed by “YES” or “NO”,”YES” means you can return it to the right position, otherwise “NO”.
 

Sample Input
2 g y g y o o w g r r o o w g r r b w b w y b y b r w g b b y o w o r y g y o g b r w o y b r w g
 

Sample Output
Case #1: YESCase #2: NO
 

题意:给出一个二阶魔方,判断这个魔方是否能否转回初始状态(判断魔方合法性)



首先,我们将魔方展开并给每个块标号,如下
  1.               1  -1
  2.              -1   1
  3.    -1   1   0   0   -1   1
  4.     1  -1   0   0    1  -1
  5.               1  -1
  6.              -1   1
  7.               0   0
  8.               0   0
其中0代表两个对立面在原位置
现在在脑海中模拟一下魔方的旋转,可以轻易发现此时对立面无论怎么旋转其和值余3均为0,cuber都知道的结论。(具体证明见官方题解)
那么现在将一组对立面在原位置情况和不再原位置情况的值加起来判断是否能整出三即可

#include<cstring>#include<string>#include<cstdio>#include<iostream>using namespace std;int a[]={1,-1,-1,1,-1,1,0,0,-1,1,1,-1,0,0,1,-1,1,-1,-1,1,0,0};int main(){    int T;    scanf("%d",&T);    int c=1;    while(T--)    {        char s[10];        int ans=0;        for(int i=1;i<=24;i++)        {            scanf("%s",s);            if(s[0]=='w'||s[0]=='y')            {                ans+=a[i-1];            }        }        printf("Case #%d: ",c++);        if(ans%3==0) printf("YES\n");        else printf("NO\n");    }}


0 0