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
题目说一个2*2的魔方能不能在一步之内把它还原
直接模拟,用数组存24 个数,转动后改变数组看能否还原。
代码如下:
#include<stdio.h>
int mp[100],a[100];
int judge()
{
for(int i=0;i<6;i++)
{
int t=i*4;
for(int j=0;j<4;j++)
{
if(a[t]!=a[t+j])
return 0;
}
}
return 1;
}
void fun()
{
for(int i=0;i<24;i++)
a[i]=mp[i];
a[1]=mp[13];a[3]=mp[15];
a[5]=mp[1];a[7]=mp[3];
a[9]=mp[5];a[11]=mp[7];
a[13]=mp[9];a[15]=mp[11];
if(judge())
{
printf("YES\n");
return;
}
for(int i=0;i<24;i++)
a[i]=mp[i];
a[1]=mp[5];a[3]=mp[7];
a[5]=mp[9];a[7]=mp[11];
a[9]=mp[13];a[11]=mp[15];
a[13]=mp[1];a[15]=mp[3];
if(judge())
{
printf("YES\n");
return;
}
for(int i=0;i<24;i++)
a[i]=mp[i];
a[0]=mp[20];a[1]=mp[21];
a[20]=mp[11];a[21]=mp[10];
a[11]=mp[16];a[10]=mp[17];
a[16]=mp[0];a[17]=mp[1];
if(judge())
{
printf("YES\n");
return;
}
for(int i=0;i<24;i++)
a[i]=mp[i];
a[0]=mp[16];a[1]=mp[17];
a[16]=mp[11];a[17]=mp[10];
a[11]=mp[20];a[10]=mp[21];
a[20]=mp[0];a[21]=mp[1];
if(judge())
{
printf("YES\n");
return;
}
for(int i=0;i<24;i++)
a[i]=mp[i];
a[12]=mp[21];a[13]=mp[23];
a[21]=mp[7];a[23]=mp[6];
a[7]=mp[18];a[6]=mp[16];
a[18]=mp[12];a[16]=mp[13];
if(judge())
{
printf("YES\n");
return;
}
for(int i=0;i<24;i++)
a[i]=mp[i];
a[12]=mp[18];a[13]=mp[16];
a[21]=mp[12];a[23]=mp[13];
a[7]=mp[21];a[6]=mp[23];
a[18]=mp[7];a[16]=mp[6];
if(judge())
{
printf("YES\n");
return;
}
printf("NO\n");
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
for(int i=0;i<24;i++)
{
scanf("%d",&mp[i]);
a[i]=mp[i];
}
if(judge())
{
printf("YES\n");
continue;
}
fun();
}
return 0;
}