1. 程式人生 > >HDU--5983 Pocket Cube

HDU--5983 Pocket Cube

連結:https://www.nowcoder.com/acm/contest/207/B
來源:牛客網
 

題目描述

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. 

輸入描述:

 

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.

 

 

輸出描述:

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

示例1

輸入

複製

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

輸出

複製

YES
YES
YES
NO

 

問一步能不能還原二階魔方,思路很簡單,但是很複雜的模擬題

七種情況   六個函式  兩個小時  200行程式碼  。。。六個函式fun 分別代表著  前後左右上下六個面的  順時針旋轉操作

一不小心就弄錯了

順時針一次是順  三次是逆   四次是返回  6*4次操作

 

#include<bits/stdc++.h>
using namespace std;
int m[6][4];
 
bool check()
{
   for(int i=0;i<6;i++)
   {
       if(m[i][0]==m[i][1]&&m[i][0]==m[i][2]&&m[i][0]==m[i][3])
        continue;
       else
        return false;
   }
   return true;
}
void ceshun(int &a,int &b,int & c,int&d,int &e,int &f,int &g,int &h)
{
 
  int t;
  t=a;
  a=c;
  c=t;
  t=b;
  b=d;
  d=t;
 t=e;
  e=c;
  c=t;
 t=d;
  d=f;
  f=t;
  t=g;
  g=e;
  e=t;
 t=f;
  f=h;
  h=t;
 
 
}
void mianshun(int & a,int &b,int &c,int &d)
{
    int t;
   t=a;
  a=b;
  b=t;
    t=b;
  b=c;
  c=t;
    t=d;
  d=c;
  c=t;
}
void fun0()
{
    ceshun(m[5][2],m[5][0],m[3][3],m[3][2],m[4][1],m[4][3],m[1][0],m[1][1]);
    mianshun(m[0][3],m[0][1],m[0][0],m[0][2]);
}
void fun1()
{
    ceshun(m[0][3],m[0][2],m[4][3],m[4][2],m[2][0],m[2][1],m[5][3],m[5][2]);
    mianshun(m[1][1],m[1][0],m[1][2],m[1][3]);
}
void fun2()
{
    ceshun(m[5][1],m[5][3],m[1][3],m[1][2],m[4][2],m[4][0],m[3][1],m[3][0]);
    mianshun(m[2][3],m[2][1],m[2][0],m[2][2]);
}
void fun3()
{
    ceshun(m[0][0],m[0][1],m[5][0],m[5][1],m[2][3],m[2][2],m[4][0],m[4][1]);
    mianshun(m[3][2],m[3][3],m[3][1],m[3][0]);
}
void fun4()
{
    ceshun(m[0][2],m[0][0],m[3][2],m[3][0],m[2][2],m[2][0],m[1][2],m[1][0]);
    mianshun(m[4][3],m[4][1],m[4][0],m[4][2]);
}
void fun5()
{
    ceshun(m[0][1],m[0][3],m[1][1],m[1][3],m[2][1],m[2][3],m[3][1],m[4][3]);
    mianshun(m[5][0],m[5][2],m[5][3],m[5][1]);
}
int main()
{
 
   int n,i,j;
   cin>>n;
 
   while(n--)
   {
       
      for(i=0;i<6;i++)
      {
          for(j=0;j<4;j++)
          {
              scanf("%d",&m[i][j]);
             
          }
      }
     
      if(check())
      {
          printf("YES\n");
         continue;
      }
      fun1();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun1();
      fun1();
      if(check())
      {
          printf("YES\n");
           continue;
      }
      fun1();
      int t;
      fun0();
      if(check())
      {
          printf("YES\n");
           continue;
      }
      fun0();
      fun0();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun0();
      fun2();
      if(check())
      {
          printf("YES\n");
           continue;
      }
      fun2();
      fun2();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun2();
      fun3();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun3();
      fun3();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun3();
      fun4();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun4();
      fun4();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun4();
      fun5();
      if(check())
      {
          printf("YES\n");
           continue;
      }
      fun5();
      fun5();
      if(check())
      {
          printf("YES\n");
            continue;
      }
      fun5();
      printf("NO\n");
   }
 
 
    return 0;
}