Pocket Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
题意是说给出一个2X2的魔方,问只移动一次(移动规则和普通魔方一样),能否使这个魔方变成每个面的数字都全是相同的样子。
没什么多说的,各种情况分出来模拟就可以了。
下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int T;
int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;
int flag1,flag2,flag3,flag4,flag5,flag6;
scanf("%d",&T);
while(T--)
{
flag1=flag2=flag3=flag4=flag5=flag6=0;
scanf("%d%d%d%d",&a,&b,&c,&d);//1
scanf("%d%d%d%d",&e,&f,&g,&h);//2
scanf("%d%d%d%d",&i,&j,&k,&l);//1
scanf("%d%d%d%d",&m,&n,&o,&p);//2
scanf("%d%d%d%d",&q,&r,&s,&t);//3
scanf("%d%d%d%d",&u,&v,&w,&x);//3
if(a==b&&a==c&&a==d)
flag1=1;
if(e==f&&e==g&&e==h)
flag2=1;
if(i==j&&i==k&&i==l)
flag3=1;
if(m==n&&m==o&&m==p)
flag4=1;
if(q==r&&q==s&&q==t)
flag5=1;
if(u==v&&u==w&&u==x)
flag6=1;
if(flag1==1&&flag3==1&&flag2==1&&flag4==1&&flag5==1&&flag6==1)
{
cout<<"YES"<<endl;
continue;
}
if(flag1==1&&flag3==1)
{
if(e==f&&e==v&&e==x&&u==w&&u==m&&u==n&&o==p&&o==q&&o==s&&r==t&&r==g&&r==h)
{
cout<<"YES"<<endl;
continue;
}
else if(u==w&&u==g&&u==h&&e==f&&e==q&&e==s&&t==r&&t==m&&t==n&&o==p&&o==v&&o==x)
{
cout<<"YES"<<endl;
continue;
}
else
{
cout<<"NO"<<endl;
continue;
}
}
else if(flag2==1&&flag4==1)
{
if(c==d&&c==q&&c==r&&s==t&&s==k&&s==l&&i==j&&i==u&&i==v&&w==x&&w==a&&w==b)
{
cout<<"YES"<<endl;
continue;
}
else if(c==d&&c==u&&c==v&&w==x&&w==k&&w==l&&i==j&&i==q&&i==r&&s==t&&s==a&&s==b)
{
cout<<"YES"<<endl;
continue;
}
else
{
cout<<"NO"<<endl;
continue;
}
}
else if(flag5==1&&flag6==1)
{
if(a==c&&a==f&&a==h&&e==g&&e==j&&e==l&&i==k&&i==n&&i==p&&m==o&&m==b&&m==d)
{
cout<<"YES"<<endl;
continue;
}
else if(a==c&&a==n&&a==p&&e==g&&e==b&&e==d&&i==k&&i==f&&i==h&&m==o&&m==j&&m==l)
{
cout<<"YES"<<endl;
continue;
}
else
{
cout<<"NO"<<endl;
continue;
}
}
else
{
cout<<"NO"<<endl;
continue;
}
}
return 0;
}