subject
The second-order magic cube is a magic cube with only two layers, consisting of only eight small pieces.
As shown in Figure p1.png.
Xiao Ming is very naughty. He only likes three colors, so he repainted the second-order magic cube of his family. The following is the following:
Front: Orange
Right: Green
Top: Yellow
Left: Green
Below: Orange
Back: Yellow
Please calculate how many different states there are when such cubes are disrupted.
If the two states rotate through the magic cube, and the colors of all sides are the same, they are considered to be the same state.
Please submit an integer representing the number of states, and do not fill in any redundant content or explanatory text.
Code
#include <vector> #include <set> #include <iostream> using namespace std; typedef char st[8][7]; st start = {{"oybbgb"}, {"oygbbb"}, {"bygbby"}, {"bybbgy"}, {"obbogb"}, {"obgobb"}, {"bbgoby"}, {"bbbogy"}}; st q[4000000]; set<string> all_state; int ans, front, tail; string to_string(st &a) { string ans; for (int i = 0; i < 8; ++i) { ans += a[i]; } return ans; } //The rotation of the upper block and the relative position change of the surface void ucell(char *a) { swap(a[0], a[2]); swap(a[2], a[5]); swap(a[5], a[4]); } //Clockwise rotation of upper layer void u(st &s) { ucell(s[0]); ucell(s[1]); ucell(s[2]); ucell(s[3]); // Relative Position Exchange of Blocks swap(s[1], s[0]); swap(s[2], s[1]); swap(s[3], s[2]); } //The rotation of the right layer is the change of the position of the plane. void rcell(char *a) { swap(a[1], a[0]); swap(a[0], a[3]); swap(a[3], a[5]); } void r(st &s)//Clockwise rotation of the right layer of the Rubik's Cube { rcell(s[1]); rcell(s[2]); rcell(s[6]); rcell(s[5]); // Block position change swap(s[2], s[1]); swap(s[5], s[1]); swap(s[6], s[5]); } void fcell(char *a) { swap(a[2], a[1]); swap(a[1], a[4]); swap(a[4], a[3]); } void f(st &s)//The front layer turns clockwise { fcell(s[0]); fcell(s[1]); fcell(s[4]); fcell(s[5]); swap(s[1], s[5]); swap(s[0], s[1]); swap(s[4], s[0]); } void uwhole(st &s)//The whole cube is clockwise from the top to be used for weighting. { u(s);//Upper rotation // Lower level rotation ucell(s[4]); ucell(s[5]); ucell(s[6]); ucell(s[7]); // After spinning, the position of the block changes swap(s[5], s[4]); swap(s[6], s[5]); swap(s[7], s[6]); } void fwhole(st &s)//The whole magic cube turns clockwise from the front to weigh { f(s); fcell(s[2]); fcell(s[6]); fcell(s[7]); fcell(s[3]); swap(s[2], s[6]); swap(s[3], s[2]); swap(s[7], s[3]); } void rwhole(st &s)//The whole magic cube turns clockwise from the right to weigh { r(s); rcell(s[0]); rcell(s[3]); rcell(s[4]); rcell(s[7]); swap(s[3], s[7]); swap(s[0], s[3]); swap(s[4], s[0]); } bool try_insert(st &s) { st k; memcpy(k, s, sizeof(start)); for (int i = 0; i < 4; i++) { fwhole(k); for (int j = 0; j < 4; j++) { uwhole(k); for (int q = 0; q < 4; q++) { rwhole(k); if (all_state.count(to_string(k)) == 1) { return false; } } } } all_state.insert(to_string(k)); return true; } void solve() { front = 0; tail = 1; all_state.insert(to_string(start)); memcpy(q[front], start, sizeof(start));//Fill q[0], which is equivalent to the first state being queued while (front < tail) { /*Attempt to add all its variants to set*/ memcpy(q[tail], q[front], sizeof(start));//Copy to tail u(q[tail]);//Clockwise rotation of upper layer if (try_insert(q[tail])) { tail++;//Extended queue } memcpy(q[tail], q[front], sizeof(start));//Copy to tail r(q[tail]);//Clockwise rotation of the right layer if (try_insert(q[tail])) { tail++;//Extended queue } memcpy(q[tail], q[front], sizeof(start));//Copy to tail f(q[tail]);//Front clockwise rotation if (try_insert(q[tail])) { tail++;//Extended queue } front++;//Pop-up team leader // cout << front << " " << tail << endl; } cout << front << endl; } int main(int argc, const char *argv[]) { solve(); return 0; }