HDU - 5983 Pocket Cube

Description

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

#include<stdio.h>
#include<string.h>
 
int a[30],b[30];
 
 
int judge()
{
    int i, j;
    for(i = 1; i <= 24; i += 4)
    {
        for(j = i + 1; j < i + 4; j++)
        {
            if(b[j] != b[j - 1])
                return 0;
        }
    }
    return 1;
}
void turn()
{
    for(int i = 1; i <= 24; i++)
        b[i] = a[i];
} 
int main()
{
    int t,flag;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1; i<=24; i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
        flag=judge();
        if(!flag)
        {
            b[1] = a[5];
            b[3] = a[7];
            b[5] = a[9];
            b[7] = a[11];
            b[9] = a[13];
            b[11] = a[15];
            b[13] = a[1];
            b[15] = a[3];
            flag = judge();
        }
        if(!flag)
        {
            turn();
            b[15] = a[11];
            b[13] = a[9];
            b[11] = a[7];
            b[9] = a[5];
            b[7] = a[3];
            b[5] = a[1];
            b[3] = a[15];
            b[1] = a[13];
            flag = judge();
        }
        if(!flag)
        {
            turn();
            b[1] = a[21];
            b[2] = a[22];
            b[21] = a[12];
            b[22] = a[11];
            b[12] = a[17];
            b[11] = a[18];
            b[17] = a[1];
            b[18] = a[2];
            flag = judge();
        }
        if(!flag)
        {
            turn();
            b[18] = a[11];
            b[17] = a[12];
            b[11] = a[22];
            b[12] = a[21];
            b[22] = a[2];
            b[21] = a[1];
            b[2] = a[18];
            b[1] = a[17];
            flag = judge();
        }
        if(!flag)
        {
            turn();
            b[17] = a[7];
            b[19] = a[8];
            b[7] = a[24];
            b[8] = a[22];
            b[24] = a[14];
            b[22] = a[13];
            b[14] = a[17];
            b[13] = a[19];
            flag = judge();
        }
        if(!flag)
        {
            turn();
            b[13] = a[22];
            b[14] = a[24];
            b[22] = a[8];
            b[24] = a[7];
            b[8] = a[19];
            b[7] = a[17];
            b[19] = a[13];
            b[17] = a[14];
            flag = judge();
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
发布了359 篇原创文章 · 获赞 371 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/Aibiabcheng/article/details/105354378