During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
In first line given a sequence of 24 integers ai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
NO
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
YES
In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
问二阶魔方转一步能不能还原
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[25];
int b[25];
int x[8];
int xx1[8]={2,4,6,8,10,12,23,21};
int xx2[8]={13,14,5,6,17,18,21,22};
int xx3[8]={1,2,18,20,12,11,15,13};
void init(){
for(int i=1;i<=24;i++){
a[i]=b[i];
}
}
bool c(int x1,int x2,int x3,int x4){
if(a[x1]==a[x2]&&a[x2]==a[x3]&&a[x3]==a[x4]){
return true;
}
return false;
}
bool check(){
for(int i=1;i<=21;i+=4){
if(!c(i,i+1,i+2,i+3)){
return false;
}
}
return true;
}
bool ccc(){
init();
for(int i=0;i<8;i++){
a[x[i]]=b[x[(i+10)%8]];
}
if(check()){
return true;
}
for(int i=0;i<8;i++){
a[x[i]]=b[x[(i+6)%8]];
}
if(check()){
return true;
}
return false;
}
void solve(){
for(int i=1;i<=24;i++){
cin>>b[i];
}
for(int i=0;i<8;i++){
x[i]=xx1[i];
}
if(ccc()){
cout<<"YES"<<endl;
return;
}
for(int i=0;i<8;i++){
x[i]=xx2[i];
}
if(ccc()){
cout<<"YES"<<endl;
return;
}
for(int i=0;i<8;i++){
x[i]=xx3[i];
}
if(ccc()){
cout<<"YES"<<endl;
return;
}
cout<<"NO"<<endl;
return;
}
int main(){
solve();
return 0;
}