B - Pocket Cube

题目:

The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube. 
The cube consists of 8 pieces, all corners. 
Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer. 
For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise. 
You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers. 

Input

The first line of input contains one integer N(N ≤ 30) which is the number of test cases. 
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces 
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces. 
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are 
given corresponding to the above pieces. 
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are 
given corresponding to the above pieces. 
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are 
given corresponding to the above pieces. 
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given 
corresponding to the above pieces. 
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given 
corresponding to the above pieces. 
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development 
as follows. 

+ - + - + - + - + - + - +
| q | r | a | b | u | v |
+ - + - + - + - + - + - +
| s | t | c | d | w | x |
+ - + - + - + - + - + - +
        | e | f |
        + - + - +
        | g | h |
        + - + - +
        | i | j |
        + - + - +
        | k | l |
        + - + - +
        | m | n |
        + - + - +
        | o | p |
        + - + - +

Output

For each test case, output YES if can be restored in one step, otherwise output NO.

Sample Input

4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6

Sample Output

YES
YES
YES
NO

题意:

给你一个N代表有N组测试数据,然后给你6行数字,代表一个2x2x2的魔方的meiy每一面的的数字,问你能否通过一次90度的旋转使魔方的每一面变成同一个数字;

思路:

想要做这道题,首先你的空间思维能力要强,自己在脑海中把魔方的六个面标上序号,然后每一面分成四块,然后也标上序号,这样就可以用一个二维数组来记录魔方的情况,但是在旋转的时候可以正向也可以逆向旋转,需要注意一下;

代码如下:

#include<stdio.h>
#include<string.h>

int map[7][5],a[7][5];

int check()//判断每个面是否都是同一个数字;
{
    for(int i=1;i<=6;i++)
    {
        int tt=a[i][1];
        for(int j=1;j<=4;j++)
        {
            if(a[i][j]!=tt)
                return 0;
        }
    }
    return 1;
}

void ee()
{
    for(int i=1;i<=6;i++)
    {
        for(int j=1;j<=4;j++)
        {
            a[i][j]=map[i][j];
        }
    }
}

int ww()
{
    if(check()==1)
        return 1;
        
    a[1][1]=map[5][1];
    a[1][2]=map[5][2];
    a[3][3]=map[6][2];
    a[3][4]=map[6][1];
    a[5][1]=map[3][4];
    a[5][2]=map[3][3];
    a[6][1]=map[1][1];
    a[6][2]=map[1][2];
    if(check()==1)
        return 1;
        
    ee();
    a[1][1]=map[6][1];
    a[1][2]=map[6][2];
    a[3][3]=map[5][2];
    a[3][4]=map[5][1];
    a[5][1]=map[1][1];
    a[5][2]=map[1][2];
    a[6][1]=map[3][4];
    a[6][2]=map[3][3];
    if(check()==1)
        return 1;
        
    ee();
    a[1][2]=map[4][2];
    a[1][4]=map[4][4];
    a[2][2]=map[1][2];
    a[2][4]=map[1][4];
    a[3][2]=map[2][2];
    a[3][4]=map[2][4];
    a[4][2]=map[3][2];
    a[4][4]=map[3][4];
    if(check()==1)
        return 1;
        
    ee();
    a[1][2]=map[2][2];
    a[1][4]=map[2][4];
    a[2][2]=map[3][2];
    a[2][4]=map[3][4];
    a[3][2]=map[4][2];
    a[3][4]=map[4][4];
    a[4][2]=map[1][2];
    a[4][4]=map[1][4];
    if(check()==1)
        return 1;
        
    ee();
    a[2][1]=map[6][3];
    a[2][2]=map[6][1];
    a[4][4]=map[5][2];
    a[4][3]=map[5][4];
    a[5][2]=map[2][1];
    a[5][4]=map[2][2];
    a[6][3]=map[4][4];
    a[6][1]=map[4][3];
    if(check()==1)
    {
        return 1;
    }
    
    ee();
    a[2][1]=map[5][2];
    a[2][2]=map[5][4];
    a[4][4]=map[6][3];
    a[4][3]=map[6][1];
    a[5][2]=map[4][4];
    a[5][4]=map[4][3];
    a[6][3]=map[2][1];
    a[6][1]=map[2][2];
     if(check()==1)
    {
        return 1;
    }
    
    return 0;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1;i<=6;i++)
        {
            for(int j=1;j<=4;j++)
            {
                scanf("%d",&map[i][j]);
                a[i][j]=map[i][j];//把数组map的值赋给a,用来存储原始的魔方状态;
            }
        }
        int kk=ww();
        if(kk==0)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值