HDU5983 Pocket Cube 【模拟】

来源:互联网 发布:9860计算器怎么编程 编辑:程序博客网 时间:2024/05/01 16:54
Pocket CubeTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 440    Accepted Submission(s): 151Problem DescriptionThe 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.InputThe 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 pieceslabelled 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 aregiven 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 aregiven 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 aregiven 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 givencorresponding 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 givencorresponding 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 developmentas 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 |        + - + - +OutputFor each test case, output YES if can be restored in one step, otherwise output NO.Sample Input41 1 1 12 2 2 23 3 3 34 4 4 45 5 5 56 6 6 66 6 6 61 1 1 12 2 2 23 3 3 35 5 5 54 4 4 41 4 1 42 1 2 13 2 3 24 3 4 35 5 5 56 6 6 61 3 1 32 4 2 43 1 3 14 2 4 25 5 5 56 6 6 6Sample OutputYESYESYESNOSource2016ACM/ICPC亚洲区青岛站-重现赛(感谢中国石油大学)

好恶心….
直接模拟每种情况 另外 必须每个面颜色都不一样(题面完全没讲)

#include<iostream>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<ctime>#include <string.h>using namespace std;#define ll long long#define pii pair<int,int>#define INF 10000000007int cube[6][4];int t[6][4];int preCube[6][4];bool check(){    for(int i=0;i<6;++i){        for(int j=1;j<4;++j){            if(t[i][j]!=t[i][0]){                return false;            }        }    }    for(int i=0;i<6;++i){        for(int j=0;j<i;++j){            if(t[i][0]==t[j][0]){                return false;            }        }    }    return true;}void initT(){    for(int i=0;i<6;++i){        for(int j=0;j<4;++j){            t[i][j]=cube[i][j];        }    }}bool slove(){    initT();    if(check()){        return true;    }    int x0=t[3][0],x2=t[3][2];    for(int i=2;i>=0;--i){        t[i+1][0]=t[i][0];        t[i+1][2]=t[i][2];    }    t[0][0]=x0,t[0][2]=x2;    if(check()){        return true;    }    initT();    x0=t[0][0],x2=t[0][2];    for(int i=1;i<=3;++i){        t[i][0]=t[i-1][0];        t[i][2]=t[i-1][2];    }    t[3][0]=x0,t[3][2]=x2;    if(check()){        return true;    }    initT();//右下    int x1=t[3][1],x3=t[3][3];    for(int i=2;i>=0;--i){        t[i+1][1]=t[i][1];        t[i+1][3]=t[i][3];    }    t[0][1]=x1,t[0][3]=x3;    if(check()){        return true;    }    initT();//右上    x1=t[0][1],x3=t[0][3];    for(int i=1;i<=3;++i){        t[i][1]=t[i-1][3];        t[i][1]=t[i-1][3];    }    t[3][1]=x1,t[3][3]=x3;    if(check()){        return true;    }    return false;}void change1302(int i,int j){    cube[i][0]=preCube[j][1];    cube[i][1]=preCube[j][3];    cube[i][2]=preCube[j][0];    cube[i][3]=preCube[j][2];}int main(){    //freopen("/home/lu/Documents/r.txt","r",stdin);    int T;    scanf("%d",&T);    while(T--){        for(int i=0;i<6;++i){            for(int j=0;j<4;++j){                scanf("%d",&preCube[i][j]);                cube[i][j]=preCube[i][j];            }        }        if(slove()){            puts("YES");        }        else{            initT();            change1302(0,0);            change1302(4,3);            change1302(5,1);            change1302(1,4);            change1302(3,5);            cube[2][0]=preCube[2][2];            cube[2][1]=preCube[2][0];            cube[2][2]=preCube[2][3];            cube[2][3]=preCube[2][1];            if(slove()){                puts("YES");            }            else{                initT();                change1302(0,1);                change1302(4,0);                change1302(5,2);                cube[1][0]=preCube[4][3];                cube[1][1]=preCube[4][2];                cube[1][2]=preCube[4][1];                cube[1][3]=preCube[4][0];                cube[2][0]=preCube[3][2];                cube[2][1]=preCube[3][0];                cube[2][2]=preCube[3][3];                cube[2][3]=preCube[3][1];                cube[3][0]=preCube[5][0];                cube[3][1]=preCube[5][1];                cube[3][2]=preCube[5][2];                cube[3][3]=preCube[5][3];                puts(slove()?"YES":"NO");            }        }    }    return 0;}
0 0