+ - + - + - + - + - + - + | 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 6Sample Output
YES YES YES NO
题意,给出一个2阶魔方,输入的24个数是按照图上a-x输入的,问一步之内是否能还原魔方.
说出来你可能不信,比赛的时候我为了做这个题,还自己做了个2阶魔方,根据题目给的图将24块按照a-x编号为1-24;
然后就发现一共就6种转法,然后暴力枚举6种转法就ac了23333333.
#include
using namespace std;
int a[30], b[30];
int judge()
{
int i, j;
for(i = 1;i <= 24;i += 4)
{
for(j = i + 1;j < i + 4;j++)
{
if(b[j] != b[j - 1])
return 0;
}
}
return 1;
}
void cpy()
{
for(int i = 1;i <= 24;i++)
b[i] = a[i];
}
int main()
{
ios::sync_with_stdio(false);
int t;
int i, flag;
cin>>t;
while(t--)
{
for(i = 1;i <= 24;i++)
{
cin>>a[i];
b[i] = a[i];
}
flag = judge();
if(!flag)
{
b[1] = b[5];
b[3] = b[7];
b[5] = b[9];
b[7] = b[11];
b[9] = b[13];
b[11] = b[15];
b[13] = a[1];
b[15] = a[3];
flag = judge();
if(!flag)
{
cpy();
b[15] = b[11];
b[13] = b[9];
b[11] = b[7];
b[9] = b[5];
b[7] = b[3];
b[5] = b[1];
b[3] = a[15];
b[1] = a[13];
flag = judge();
}
}
if(!flag)
{
cpy();
b[1] = b[21];
b[2] = b[22];
b[21] = b[12];
b[22] = b[11];
b[12] = b[17];
b[11] = b[18];
b[17] = a[1];
b[18] = a[2];
flag = judge();
if(!flag)
{
cpy();
b[18] = b[11];
b[17] = b[12];
b[11] = b[22];
b[12] = b[21];
b[22] = b[2];
b[21] = b[1];
b[2] = a[18];
b[1] = a[17];
flag = judge();
}
}
if(!flag)
{
cpy();
b[17] = b[7];
b[19] = b[8];
b[7] = b[24];
b[8] = b[22];
b[24] = b[14];
b[22] = b[13];
b[14] = a[17];
b[13] = a[19];
flag = judge();
if(!flag)
{
cpy();
b[13] = b[22];
b[14] = b[24];
b[22] = b[8];
b[24] = b[7];
b[8] = b[19];
b[7] = b[17];
b[19] = a[13];
b[17] = a[14];
flag = judge();
}
}
if(flag)
cout<<"YES"<