题意:给了一个2*2的魔方..每步操作可以将任意一面翻转90度..现在问在N(<=7)步内.最多能翻出几面相同的.
直接打表模拟每种翻转情况
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 7 int B[6][24]= { {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23}, //ok 8 {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23}, //ok 9 {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8}, //ok 10 {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4}, //ok 11 {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23}, //ok 12 {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23} //ok 13 }; 14 int ans=0; 15 void update(int *h) { 16 int sum=0; 17 if (h[0]==h[1] && h[1]==h[2] && h[2]==h[3]) sum++; 18 if (h[4]==h[5] && h[5]==h[10] && h[10]==h[11]) sum++; 19 if (h[6]==h[7] && h[7]==h[12] && h[12]==h[13]) sum++; 20 if (h[8]==h[9] && h[9]==h[14] && h[14]==h[15]) sum++; 21 if (h[16]==h[17] && h[17]==h[18] && h[18]==h[19]) sum++; 22 if (h[20]==h[21] && h[21]==h[22] && h[22]==h[23]) sum++; 23 ans=max(ans,sum); 24 } 25 void dfs(int N,int *h) { 26 update(h); 27 if(N==0) return; 28 int p[24]; 29 for(int i=0; i<6; i++) { 30 for(int j=0; j<24; j++) { 31 p[j]=h[B[i][j]]; 32 } 33 dfs(N-1,p); 34 } 35 return; 36 } 37 int main() { 38 int n; 39 while(~scanf("%d",&n)) { 40 int p[25]; 41 ans=0; 42 for(int i=0; i<24; i++) 43 scanf("%d",&p[i]); 44 dfs(n,p); 45 printf("%d\n",ans); 46 } 47 }