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;
}

猜你喜欢

转载自blog.csdn.net/swustzhaoxingda/article/details/83049001
今日推荐