HDU 5292 Pocket Cube (结论题)

Pocket Cube

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


 

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: YES Case #2: NO

 

题意:给你一个二阶魔方问你是否能够还原。

思路:结论题。这个展开图底面和顶面格子权值为0,其他格子为1,-1,-1,1然后当该方格为黄色或白色时(其他对色组也可),加上方格上的权值。总和为3的倍数时可还原,否则不可以。

qsc的证明:必要性:从一个已经还原好的魔方出发,初始权值和为三的倍数。在旋转一个面的时候,权值和mod3不会发生变化。充分性:局部调整法。对于相邻的角块,可进行图(2)和图(3)不改变其他角块的变化。还原7个块后,mod3不变,第8块也已还原。

代码:

#include<bits/stdc++.h>
#define ll long long
#define maxn 410
#define inf 0x3f3f3f3f
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
using namespace std;
char s[maxn];
int n,m,flag;
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,cas=1;
   scanf("%d",&T);
    {
        while(T--){
        //getchar();
        int ans=0;
        for(int i=0;i<24;i++)
        {
           scanf("%s",s);
           if(s[0]=='w'||s[0]=='y')ans+=a[i];
        }
        flag=(ans%3==0?1:0);
        printf("Case #%d: %s\n",cas++,flag?"YES":"NO");
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值