1 /*part of the copyright and version statement of the program:2 **copyright (c) 2016, undergraduate3 **all rights reserved.4 * * FileName: Single even n-order Rubik's Cube matrix5 * * Program function: Single even n-order Rubik's Cube matrix6 **amoshen7 * * Completion date: 2016.11.28 * * Version number: V1.09 */Ten#include <iostream> One A using namespacestd; - - #defineMax_size 100 the - intMainvoid) - { - intM,u,n,row,cie,row1,cie1,i,j;//Row is line, CIE is column, ROW1 is temporary row variable, CIE1 is temporary column variable, I,J represents row variable and column variable respectively + intMagic[max_size][max_size] = {0},b[max_size][max_size] = {0},ex[max_size][max_size] = {0}; - +cout <<"Please enter M, note: n = (2 * m + 1), or M input 1, to get a 6-order Rubik's Cube matrix"<<Endl; Acout <<"m ="; atCIN >>m; - -n =2*(2* m +1); -U = n/2; - //fill the first U*u magic array First -ROW =0; inCIE = (U-1)/2; - toMagic[row][cie] =1; +B[row][cie] =1; - the for(i =2; I <= (u*u); i++) * { $ROW1 = ROW-1;Panax NotoginsengCIE1 = CIE +1; - the if(ROW1 <0) + { AROW1 = U-1; the } + if(CIE1 > (U-1)) - { $CIE1 =0; $ } - - if(B[row1][cie1] = =0) the { -ROW =ROW1;WuyiCIE =CIE1; theMagic[row][cie] =i; -B[row][cie] =1; Wu } - Else About { $row = row +1; - if(ROW = =u) - { -ROW =0; A } +Magic[row][cie] =i; theB[row][cie] =1; - } $ } the //Refill the Fourth Magic Array (lower right corner) the for(i = U;i <2*u;i++) the { the for(j = U;j <2*u;j++) - { inMAGIC[I][J] = Magic[i-u][j-u] + u*u; the } the } About //Upper Right Corner the for(i =0; I < u;i++) the { the for(j = U;j <2*u;j++) + { -MAGIC[I][J] = Magic[i+u][j] + u*u; the }Bayi } the //Lower left corner the for(i = U;i <2*u;i++) - { - for(j =0; J < u;j++) the { theMAGIC[I][J] = Magic[i-u][j+u] + u*u; the } the } - //the upper right corner and the lower right corner of the exchange the for(i =0; I < u;i++) the { the for(j =2*u-1; J > (2*U-M); j--)94 { theEX[I][J] =Magic[i][j]; theMAGIC[I][J] = magic[i+U] [j]; the }98 } About for(i =0; I < u;i++) - {101 for(j =2*u-1; J > (2*U-M); j--)102 {103MAGIC[I+U][J] =Ex[i][j];104 } the }106 //The upper -left corner and the lower-left corner of the exchange107 for(i =0; I < u;i++)108 {109 if(i = = (U1)/2) the {111 for(j =1; J <= m;j++) the {113EX[I][J] =Magic[i][j]; theMAGIC[I][J] = magic[i+U] [j]; the } the }117 Else118 {119 for(j =0; J < m;j++) - {121EX[I][J] =Magic[i][j];122MAGIC[I][J] = magic[i+U] [j];123 }124 } the }126 for(i =0; I < u;i++)127 { - if(i = = (U1)/2)129 { the for(j =1; J <= m;j++)131 { theMAGIC[I+U][J] =Ex[i][j];133 }134 }135 Else136 {137 for(j =0; J < m;j++)138 {139MAGIC[I+U][J] =Ex[i][j]; $ }141 }142 }143 144cout << N <<"Order cube Matrix:"<<Endl;145 146 for(i =0; I <2*u;i++)147 {148 for(j =0; J <2*u;j++)149 { Maxcout << Magic[i][j] <<'\ t';151 } thecout <<Endl;153 }154 155 return 0;156}
Principle
Because it is a single even n = (2*m + 1), if the entire matrix is divided into 4 parts, each part is an odd order, using the odd-order algorithm to fill.
()
After the completion of the
Swap b and C in the rightmost m-1 column
The middle row of a, starting from the second column, M lattice corresponds to the D interchange, the remainder begins at the far left and the M lattice corresponds to the D interchange
After the exchange of the final
"C + + small white growth"--(continued) Single even n-order Rubik's Cube matrix