zoukankan      html  css  js  c++  java
  • Pocket Cube

    Pocket Cube

    http://acm.hdu.edu.cn/showproblem.php?pid=5983

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


    Problem 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
     
    Source

    纯模拟= =,训练的时候脑抽没写出来

      1 #include<iostream>
      2 #include<cstring>
      3 #include<string>
      4 #include<cmath>
      5 #include<cstdio>
      6 #include<algorithm>
      7 #include<vector>
      8 #define maxn 200005
      9 #define lson l,mid,rt<<1
     10 #define rson mid+1,r,rt<<1|1
     11 using namespace std;
     12 
     13 int map[7][5];
     14 
     15 bool Check(){
     16     int flag;
     17     for(int i=1;i<=6;i++){
     18         flag=map[i][1];
     19         for(int j=2;j<=4;j++){
     20             if(flag!=map[i][j]){
     21                 return false;
     22             }
     23         }
     24     }
     25     return true;
     26 }
     27 
     28 int _init_[7][5];
     29 
     30 void init(){
     31     for(int i=1;i<=6;i++){
     32         for(int j=1;j<=4;j++){
     33             map[i][j]=_init_[i][j];
     34         }
     35     }
     36 }
     37 
     38 int main(){
     39 
     40     int t;
     41     cin>>t;
     42     while(t--){
     43         for(int i=1;i<=6;i++){
     44             for(int j=1;j<=4;j++){
     45                 cin>>_init_[i][j];
     46             }
     47         }
     48         int tmp1,tmp2;
     49         init();
     50         if(Check()){
     51             cout<<"YES"<<endl;
     52             continue;
     53         }
     54         //1
     55         init();
     56         tmp1=map[1][1],tmp2=map[1][3];
     57         map[1][1]=map[2][1],map[1][3]=map[2][3];
     58         map[2][1]=map[3][1],map[2][3]=map[3][3];
     59         map[3][1]=map[4][1],map[3][3]=map[4][3];
     60         map[4][1]=tmp1,map[4][3]=tmp2;
     61         if(Check()){
     62             cout<<"YES"<<endl;
     63             continue;
     64         }
     65         init();
     66         tmp1=map[1][1],tmp2=map[1][3];
     67         map[1][1]=map[4][1],map[1][3]=map[4][3];
     68         map[4][1]=map[3][1],map[4][3]=map[3][3];
     69         map[3][1]=map[2][1],map[3][3]=map[2][3];
     70         map[2][1]=tmp1,map[2][3]=tmp2;
     71         if(Check()){
     72             cout<<"YES"<<endl;
     73             continue;
     74         }
     75         //2
     76         init();
     77         tmp1=map[2][1],tmp2=map[2][2];
     78         map[2][1]=map[6][3],map[2][2]=map[6][1];
     79         map[6][3]=map[4][4],map[6][1]=map[4][3];
     80         map[4][4]=map[5][2],map[4][3]=map[5][4];
     81         map[5][2]=tmp1,map[5][4]=tmp2;
     82         if(Check()){
     83             cout<<"YES"<<endl;
     84             continue;
     85         }
     86         init();
     87         tmp1=map[5][2],tmp2=map[5][4];
     88         map[5][2]=map[4][4],map[5][4]=map[4][3];
     89         map[4][4]=map[6][3],map[4][3]=map[6][1];
     90         map[6][3]=map[2][1],map[6][1]=map[2][2];
     91         map[2][1]=tmp1,map[2][2]=tmp2;
     92         if(Check()){
     93             cout<<"YES"<<endl;
     94             continue;
     95         }
     96         //3
     97         init();
     98         tmp1=map[3][1],tmp2=map[3][2];
     99         map[3][1]=map[6][4],map[3][2]=map[6][3];
    100         map[6][4]=map[1][4],map[6][3]=map[1][3];
    101         map[1][4]=map[5][4],map[1][3]=map[5][3];
    102         map[5][4]=tmp1,map[5][3]=tmp2;
    103         if(Check()){
    104             cout<<"YES"<<endl;
    105             continue;
    106         }
    107         init();
    108         tmp1=map[5][4],tmp2=map[5][3];
    109         map[5][4]=map[1][4],map[5][3]=map[1][3];
    110         map[1][4]=map[6][4],map[1][3]=map[6][3];
    111         map[6][4]=map[3][1],map[6][3]=map[3][2];
    112         map[3][1]=tmp1,map[3][2]=tmp2;
    113         if(Check()){
    114             cout<<"YES"<<endl;
    115             continue;
    116         }
    117         cout<<"NO"<<endl;
    118     }
    119 
    120 }
    View Code
  • 相关阅读:
    linux常用的一些访问目录
    专业术语
    java基础知识回顾之javaIO类--File类应用:获取指定目录下面的指定扩展名的文件,将文件的绝对路径写入到目的文件当中
    java基础知识回顾之javaIO类--File类应用:删除带内容的目录
    java基础知识回顾之javaIO类--File类应用:过滤器接口FilenameFilter和FileFilter
    java基础知识回顾之javaIO类--File类应用:递归深度遍历文件
    java基础知识回顾之javaIO类--File类
    java基础知识回顾之java集合类-Properties集合
    java基础知识回顾之---java StringBuffer,Stringbuilder与String的区别
    java基础知识回顾之---java StringBuilder与StringBuffer异同点
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/9866269.html
Copyright © 2011-2022 走看看