九峰与CFOP
九峰与CFOP
https://ac.nowcoder.com/acm/contest/9984/C
大模拟,没有什么很坑的地方,只要能理解就可以模拟出来,对于我这种魔方菜鸡都能理解
代码参照兰子大佬
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1e9 + 7;
const int N = 1e5 + 7;
const int INF = 0x3f3f3f3f;
int a[7][10]; //模拟魔方的六个面九个格子
//先给每一个格子命名
//1 2 3
//4 5 6
//7 8 9
//颜色:1-白色,2-黄色(白色的背面) ,3 4 5 6,白色相邻面
int n , m , ans1 = 0 , ans2 = 0 , ans3 = 0 , ans4 = 0;
void swap(int &x1 , int &x2 , int &x3 , int &x4){
int tmp = x1;
x1 = x4;
x4 = x3;
x3 = x2;
x2 = tmp;
} //这里是模拟旋转一下 比如U就是将最上面一层旋转一下
//那么观察就可以看到,我们就是3456的最上一层都移到左边的那一面
//还是就是顶面2顺时针转了一下
//那么用swap来做
//一共swap 3 + 2次
//3:3456面的1 2 3 每一个都和他左边的那面
//即swap(a[3][1] , a[4][1] , a[5][1] ,a[6][1])
//swap(a[3][2] , a[4][2] , a[5][2] ,a[6][2])
//swap(a[3][3] , a[4][3] , a[5][3] ,a[6][3])
//然后是顶面的变化 中间轴不动
//即swap(a[2][1],a[2][7],a[2][9],a[2][3]);
//swap(a[2][2],a[2][4],a[2][8],a[2][6]);
void rotate_(int x){ //将一个面逆时针转
swap(a[x][1],a[x][7],a[x][9],a[x][3]);
swap(a[x][2],a[x][4],a[x][8],a[x][6]);
}
void rotate(int x){ //将一个面顺时针转
swap(a[x][1],a[x][3],a[x][9],a[x][7]);
swap(a[x][2],a[x][6],a[x][8],a[x][4]);
}
//模拟操作
void U(){
for(int i = 1 ; i <= 3 ; ++i)
swap(a[3][i] , a[4][i] , a[5][i] , a[6][i]);
rotate(2);
}
void U_(){ //即U'操作 逆时针转一下相当于顺时针转三下
U() , U() , U();
}
void U2(){
U();U();
}
void R(){
swap(a[1][3] , a[3][3] , a[2][3] , a[5][7]);
swap(a[1][6] , a[3][6] , a[2][6] , a[5][4]);
swap(a[1][9] , a[3][9] , a[2][9] , a[5][1]);
rotate(6);
}
void R_(){
R() , R() , R();
}
void R2(){
R() , R();
}
void F(){//1->4->2->6->1
swap(a[1][1],a[4][3],a[2][9],a[6][7]);
swap(a[1][2],a[4][6],a[2][8],a[6][4]);
swap(a[1][3],a[4][9],a[2][7],a[6][1]);
rotate(3);
}
void F_(){
F();F();F();
}
void F2(){
F();F();
}
void D(){
for(int i=7;i<=9;i++){
swap(a[6][i],a[5][i],a[4][i],a[3][i]);
}
rotate(1);
}
void D_(){
D();D();D();
}
void D2(){
D();D();
}
void L(){
swap(a[1][1],a[5][9],a[2][1],a[3][1]);
swap(a[1][4],a[5][6],a[2][4],a[3][4]);
swap(a[1][7],a[5][3],a[2][7],a[3][7]);
rotate(4);
}
void L_(){
L();L();L();
}
void L2(){
L();L();
}
void B(){
swap(a[1][9],a[6][3],a[2][1],a[4][7]);
swap(a[1][8],a[6][6],a[2][2],a[4][4]);
swap(a[1][7],a[6][9],a[2][3],a[4][1]);
rotate(5);
}
void B_(){
B();B();B();
}
void B2(){
B();B();
}
void E(){
swap(a[6][4],a[5][4],a[4][4],a[3][4]);
swap(a[6][5],a[5][5],a[4][5],a[3][5]);
swap(a[6][6],a[5][6],a[4][6],a[3][6]);
}
void E_(){
E();E();E();
}
void E2(){
E();E();
}
void M(){
swap(a[1][2],a[5][8],a[2][2],a[3][2]);
swap(a[1][5],a[5][5],a[2][5],a[3][5]);
swap(a[1][8],a[5][2],a[2][8],a[3][8]);
}
void M_(){
M();M();M();
}
void M2(){
M();M();
}
void S(){
swap(a[1][6],a[4][8],a[2][4],a[6][2]);
swap(a[1][5],a[4][5],a[2][5],a[6][5]);
swap(a[1][4],a[4][2],a[2][6],a[6][8]);
}
void S_(){
S();S();S();
}
void S2(){
S();S();
}
void u(){
U();E_();
}
void u_(){
U_();E();
}
void u2(){
U2();E2();
}
void r(){
R();M_();
}
void r_(){
R_();M();
}
void r2(){
R2();M2();
}
void f(){
F();S();
}
void f_(){
F_();S_();
}
void f2(){
F2();S2();
}
void d(){
D();E();
}
void d_(){
D_();E_();
}
void d2(){
D2();E2();
}
void l(){
L();M();
}
void l_(){
L_();M_();
}
void l2(){
L2();M2();
}
void b(){
B();S_();
}
void b_(){
B_();S();
}
void b2(){
B2();S2();
}
void x(){
r();L_();
}
void x_(){
r_();L();
}
void x2(){
r2();L2();
}
void y(){
u();D_();
}
void y_(){
u_();D();
}
void y2(){
u2();D2();
}
void z(){
b_();F();
}
void z_(){
b();F_();
}
void z2(){
b2();F2();
}
//判断状态
bool judge_c1(){
if(a[1][2]==1&&a[1][5]==1&&a[1][8]==1&&a[1][4]==1&&a[1][6]==1&&a[3][8]==a[3][5]&&a[4][8]==a[4][5]&&a[5][8]==a[5][5]&&a[6][8]==a[6][5])
return true;
return false;
}
bool judge_c2(){
if(a[2][2]==1&&a[2][5]==1&&a[2][8]==1&&a[2][4]==1&&a[2][6]==1&&a[3][2]==a[3][5]&&a[4][2]==a[4][5]&&a[5][2]==a[5][5]&&a[6][2]==a[6][5])
return true;
return false;
}
bool judge_c3(){
if(a[3][2]==1&&a[3][5]==1&&a[3][8]==1&&a[3][4]==1&&a[3][6]==1&&a[1][2]==a[1][5]&&a[4][6]==a[4][5]&&a[2][8]==a[2][5]&&a[6][4]==a[6][5])
return true;
return false;
}
bool judge_c4(){
if(a[4][2]==1&&a[4][5]==4&&a[4][8]==1&&a[4][4]==1&&a[4][6]==1&&a[3][4]==a[3][5]&&a[1][4]==a[1][5]&&a[5][6]==a[5][5]&&a[2][4]==a[2][5])
return true;
return false;
}
bool judge_c5(){
if(a[5][2]==1&&a[5][5]==1&&a[5][8]==1&&a[5][4]==1&&a[5][6]==1&&a[2][2]==a[2][5]&&a[4][4]==a[4][5]&&a[1][8]==a[1][5]&&a[6][6]==a[6][5])
return true;
return false;
}
bool judge_c6(){
if(a[6][2]==1&&a[6][5]==1&&a[6][8]==1&&a[6][4]==1&&a[6][6]==1&&a[3][6]==a[3][5]&&a[1][6]==a[1][5]&&a[5][4]==a[5][5]&&a[2][6]==a[2][5])
return true;
return false;
}
bool judge_C(){
if(a[1][5]==1) return judge_c1();
else if(a[2][5]==1) return judge_c2();
else if(a[3][5]==1) return judge_c3();
else if(a[4][5]==1) return judge_c4();
else if(a[5][5]==1) return judge_c5();
else if(a[6][5]==1) return judge_c6();
else return false;
}
bool judge_f1(){
for(int i=1;i<=9;i++){
if(a[1][i]!=1) return false;
}
for(int i=3;i<=6;i++){
if(a[i][4]!=a[i][5]||a[i][6]!=a[i][5]||a[i][7]!=a[i][5]||a[i][8]!=a[i][5]||a[i][9]!=a[i][5]) return false;
}
return true;
}
bool judge_f2(){
for(int i=1;i<=9;i++){
if(a[2][i]!=1) return false;
}
for(int i=3;i<=6;i++){
if(a[i][4]!=a[i][5]||a[i][6]!=a[i][5]||a[i][1]!=a[i][5]||a[i][2]!=a[i][5]||a[i][3]!=a[i][5]) return false;
}
return true;
}
bool judge_f3(){
for(int i=1;i<=9;i++){
if(a[3][i]!=1) return false;
}
if(a[2][4]!=a[2][5]||a[2][6]!=a[2][5]||a[2][7]!=a[2][5]||a[2][8]!=a[2][5]||a[2][9]!=a[2][5]) return false;
if(a[4][2]!=a[4][5]||a[4][8]!=a[4][5]||a[4][3]!=a[4][5]||a[4][6]!=a[4][5]||a[4][9]!=a[4][5]) return false;
if(a[6][2]!=a[6][5]||a[6][8]!=a[6][5]||a[6][1]!=a[6][5]||a[6][4]!=a[6][5]||a[6][7]!=a[6][5]) return false;
if(a[1][4]!=a[1][5]||a[1][6]!=a[1][5]||a[1][1]!=a[1][5]||a[1][2]!=a[1][5]||a[1][3]!=a[1][5]) return false;
return true;
}
bool judge_f5(){
for(int i=1;i<=9;i++){
if(a[5][i]!=1) return false;
}
if(a[2][4]!=a[2][5]||a[2][6]!=a[2][5]||a[2][1]!=a[2][5]||a[2][2]!=a[2][5]||a[2][3]!=a[2][5]) return false;
if(a[4][2]!=a[4][5]||a[4][8]!=a[4][5]||a[4][1]!=a[4][5]||a[4][4]!=a[4][5]||a[4][7]!=a[4][5]) return false;
if(a[6][2]!=a[6][5]||a[6][8]!=a[6][5]||a[6][3]!=a[6][5]||a[6][6]!=a[6][5]||a[6][9]!=a[6][5]) return false;
if(a[1][4]!=a[1][5]||a[1][6]!=a[1][5]||a[1][7]!=a[1][5]||a[1][8]!=a[1][5]||a[1][9]!=a[1][5]) return false;
return true;
}
bool judge_f4(){
for(int i=1;i<=9;i++){
if(a[4][i]!=1) return false;
}
if(a[2][2]!=a[2][5]||a[2][8]!=a[2][5]||a[2][1]!=a[2][5]||a[2][4]!=a[2][5]||a[2][7]!=a[2][5]) return false;
if(a[5][2]!=a[5][5]||a[5][8]!=a[5][5]||a[5][3]!=a[5][5]||a[5][6]!=a[5][5]||a[5][9]!=a[5][5]) return false;
if(a[1][2]!=a[1][5]||a[1][8]!=a[1][5]||a[1][1]!=a[1][5]||a[1][4]!=a[1][5]||a[1][7]!=a[1][5]) return false;
if(a[3][2]!=a[3][5]||a[3][8]!=a[3][5]||a[3][1]!=a[3][5]||a[3][4]!=a[3][5]||a[3][7]!=a[3][5]) return false;
return true;
}
bool judge_f6(){
for(int i=1;i<=9;i++){
if(a[6][i]!=1) return false;
}
if(a[2][2]!=a[2][5]||a[2][8]!=a[2][5]||a[2][3]!=a[2][5]||a[2][6]!=a[2][5]||a[2][9]!=a[2][5]) return false;
if(a[5][2]!=a[5][5]||a[5][8]!=a[5][5]||a[5][1]!=a[5][5]||a[5][4]!=a[5][5]||a[5][7]!=a[5][5]) return false;
if(a[1][2]!=a[1][5]||a[1][8]!=a[1][5]||a[1][3]!=a[1][5]||a[1][6]!=a[1][5]||a[1][9]!=a[1][5]) return false;
if(a[3][2]!=a[3][5]||a[3][8]!=a[3][5]||a[3][3]!=a[3][5]||a[3][6]!=a[3][5]||a[3][9]!=a[3][5]) return false;
return true;
}
bool judge_F(){
if(a[1][5]==1) return judge_f1();
else if(a[2][5]==1) return judge_f2();
else if(a[3][5]==1) return judge_f3();
else if(a[4][5]==1) return judge_f4();
else if(a[5][5]==1) return judge_f5();
else if(a[6][5]==1) return judge_f6();
else return false;
}
bool judge_o1(){
if(!judge_f1()) return false;
for(int i=1;i<=9;i++){
if(a[2][i]!=a[2][5]) return false;
}
return true;
}
bool judge_o2(){
if(!judge_f2()) return false;
for(int i=1;i<=9;i++){
if(a[1][i]!=a[1][5]) return false;
}
return true;
}
bool judge_o3(){
if(!judge_f3()) return false;
for(int i=1;i<=9;i++){
if(a[5][i]!=a[5][5]) return false;
}
return true;
}
bool judge_o5(){
if(!judge_f5()) return false;
for(int i=1;i<=9;i++){
if(a[3][i]!=a[3][5]) return false;
}
return true;
}
bool judge_o4(){
if(!judge_f4()) return false;
for(int i=1;i<=9;i++){
if(a[6][i]!=a[6][5]) return false;
}
return true;
}
bool judge_o6(){
if(!judge_f6()) return false;
for(int i=1;i<=9;i++){
if(a[4][i]!=a[4][5]) return false;
}
return true;
}
bool judge_O(){
if(a[1][5]==1) return judge_o1();
else if(a[2][5]==1) return judge_o2();
else if(a[3][5]==1) return judge_o3();
else if(a[4][5]==1) return judge_o4();
else if(a[5][5]==1) return judge_o5();
else if(a[6][5]==1) return judge_o6();
else return false;
}
bool judge_P(){
for(int i=1;i<=6;i++){
for(int j=1;j<=9;j++){
if(a[i][j]!=a[i][5]) return false;
}
}
return true;
}
void check1(char s[]){ //判断读入的操作 然后进行操作
if(strcmp(s , "U") == 0) U();
else if(strcmp(s , "U'") == 0) U_();
else if(strcmp(s , "U2") == 0) U2();
else if(strcmp(s , "R") == 0) R();
else if(strcmp(s , "R'") == 0) R_();
else if(strcmp(s , "R2") == 0) R2();
else if(strcmp(s , "F") == 0) F();
else if(strcmp(s , "F'") == 0) F_();
else if(strcmp(s , "F2") == 0) F2();
else if(strcmp(s , "D") == 0) D();
else if(strcmp(s , "D'") == 0) D_();
else if(strcmp(s , "D2") == 0) D2();
else if(strcmp(s , "L") == 0) L();
else if(strcmp(s , "L'") == 0) L_();
else if(strcmp(s , "L2") == 0) L2();
else if(strcmp(s , "B") == 0) B();
else if(strcmp(s , "B'") == 0) B_();
else if(strcmp(s , "B2") == 0) B2();
else if(strcmp(s , "u") == 0) u();
else if(strcmp(s , "u'") == 0) u_();
else if(strcmp(s , "u2") == 0) u2();
else if(strcmp(s , "r") == 0) r();
else if(strcmp(s , "r'") == 0) r_();
else if(strcmp(s , "r2") == 0) r2();
else if(strcmp(s , "f") == 0) f();
else if(strcmp(s , "f'") == 0) f_();
else if(strcmp(s , "f2") == 0) f2();
else if(strcmp(s , "d") == 0) d();
else if(strcmp(s , "d'") == 0) d_();
else if(strcmp(s , "d2") == 0) d2();
else if(strcmp(s , "l") == 0) l();
else if(strcmp(s , "l'") == 0) l_();
else if(strcmp(s , "l2") == 0) l2();
else if(strcmp(s , "b") == 0) b();
else if(strcmp(s , "b'") == 0) b_();
else if(strcmp(s , "b2") == 0) b2();
else if(strcmp(s , "x") == 0) x();
else if(strcmp(s , "x'") == 0) x_();
else if(strcmp(s , "x2") == 0) x2();
else if(strcmp(s , "y") == 0) y();
else if(strcmp(s , "y'") == 0) y_();
else if(strcmp(s , "y2") == 0) y2();
else if(strcmp(s , "z") == 0) z();
else if(strcmp(s , "z'") == 0) z_();
else if(strcmp(s , "z2") == 0) z2();
else if(strcmp(s , "E") == 0) E();
else if(strcmp(s , "E'") == 0) E_();
else if(strcmp(s , "E2") == 0) E2();
else if(strcmp(s , "M") == 0) M();
else if(strcmp(s , "M'") == 0) M_();
else if(strcmp(s , "M2") == 0) M2();
else if(strcmp(s , "S") == 0) S();
else if(strcmp(s , "S'") == 0) S_();
else if(strcmp(s , "S2") == 0) S2();
}
int main(void){
for(int i = 1 ; i <= 6 ; ++i){
for(int j = 1 ; j <= 9 ; ++j){
a[i][j] = i;
}
}
cin>>n>>m;
char tmp[2];
while(n--){
cin>>tmp;
check1(tmp);
}
for(int i = 1 ; i <= m ; ++i){
cin>>tmp;
if(ans4 != 0) continue;
check1(tmp);
if(ans1 == 0) if(judge_C()) ans1 = i;
if(ans2 == 0) if(judge_F()) ans2 = i;
if(ans3 == 0) if(judge_O()) ans3 = i;
if(ans4 == 0) if(judge_P()) ans4 = i;
}
cout<<ans1<<" "<<ans2<<" "<<ans3<<" "<<ans4<<endl;
return 0;
}