hdu - 5983

Posted by WildCow on May 1, 2018

Pocket Cube

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)

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. avater

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


不就是个转魔方

我 TM 的转出来了233333
看起来有很多种情况
其实只有三种
往左转等价于往右转三次
模拟就好了
写到一半突然用起了宏定义
效果拔群
可能是我这辈子用宏定义用得最好的一次
1 Y


#include <bits/stdc++.h>
#define K1 ma[0][0]
#define K2 ma[0][1]
#define K3 ma[1][0]
#define K4 ma[1][1]
using namespace std;

const int N = 5;

struct Node
{
    int ma[N][N];
};

Node node[10];

void show()
{
    cout << endl << endl;
    printf("%d%d%d%d%d%d\n", node[4].K1, node[4].K2, node[0].K1, node[0].K2, node[5].K1, node[5].K2);
    printf("%d%d%d%d%d%d\n", node[4].K3, node[4].K4, node[0].K3, node[0].K4, node[5].K3, node[5].K4);
    printf("  %d%d  \n", node[1].K1, node[1].K2);
    printf("  %d%d  \n", node[1].K3, node[1].K4);
    printf("  %d%d  \n", node[2].K1, node[2].K2);
    printf("  %d%d  \n", node[2].K3, node[2].K4);
    printf("  %d%d  \n", node[3].K1, node[3].K2);
    printf("  %d%d  \n", node[3].K3, node[3].K4);
    cout << endl << endl;
}

bool check()
{
    int mark;
    //show();
    for(int i = 0; i < 6; i ++){
//        cout << node[i].ma[0][0] << endl;
//        cout << node[i].ma[0][1] << endl;
//        cout << node[i].ma[1][0] << endl;
//        cout << node[i].ma[1][1] << endl;
        if(!(node[i].ma[0][0] == node[i].ma[0][1] && node[i].ma[0][0] == node[i].ma[1][0] && node[i].ma[0][0] == node[i].ma[1][1])){
            return false;
        }
    }

    return true;
}

void r()
{
    int t, q;

    t = node[0].K1;
    node[0].K1 = node[0].K2;
    node[0].K2 = node[0].K4;
    node[0].K4 = node[0].K3;
    node[0].K3 = t;

    t = node[1].K1;
    q = node[1].K2;
    node[1].K1 = node[4].K2;
    node[1].K2 = node[4].K4;
    node[4].K2 = node[3].K4;
    node[4].K4 = node[3].K3;
    node[3].K4 = node[5].K3;
    node[3].K3 = node[5].K1;
    node[5].K1 = q;
    node[5].K3 = t;
}

void h()
{
    int t, q;

    t = node[1].K1;
    node[1].K1 = node[1].K2;
    node[1].K2 = node[1].K4;
    node[1].K4 = node[1].K3;
    node[1].K3 = t;

    t = node[0].K3;
    q = node[0].K4;
    node[0].K3 = node[5].K3;
    node[0].K4 = node[5].K4;
    node[5].K3 = node[2].K2;
    node[5].K4 = node[2].K1;
    node[2].K2 = node[4].K3;
    node[2].K1 = node[4].K4;
    node[4].K3 = t;
    node[4].K4 = q;
}

int b()
{
    int t, q;

    t = node[5].K1;
    node[5].K1 = node[5].K2;
    node[5].K2 = node[5].K4;
    node[5].K4 = node[5].K3;
    node[5].K3 = t;

    t = node[0].K2;
    q = node[0].K4;
    //cout << node[0].K2 << endl;
//    cout << node[3].K2 << endl;
    node[0].K2 = node[3].K2;
    node[0].K4 = node[3].K4;
//    cout << node[0].K2 << endl;
//    cout << node[3].K2 << endl;
    node[3].K2 = node[2].K2;
    node[3].K4 = node[2].K4;
    node[2].K2 = node[1].K2;
    node[2].K4 = node[1].K4;
    node[1].K2 = t;
    node[1].K4 = q;
//    check();
}

int main(int argc, char const *argv[])
{
    int ncase;
    int mark;

    scanf("%d", &ncase);
    while(ncase --){
        mark = 0;
        for(int i = 0; i < 6; i ++){
            scanf("%d%d%d%d", &node[i].ma[0][0], &node[i].ma[0][1], &node[i].ma[1][0], &node[i].ma[1][1]);
        }
        if(check()){
            mark = 1;
        }
//      b();
//      check();

        r();
        if(check()){
            mark = 1;
        }
        r();r();r();

        r();r();r();
        if(check()){
            mark = 1;
        }
        r();
        ///
        b();
        if(check()){
            mark = 1;
        }
        b();b();b();

        b();b();b();
        if(check()){
            mark = 1;
        }
        b();
        ///
        h();
        if(check()){
            mark = 1;
        }
        h();h();h();

        h();h();h();
        if(check()){
            mark = 1;
        }
        h();

        if(mark){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }


    return 0;
}