标签:col names printf code scanf font mes emc memcpy
题面有误!10,11,12操作类别为A,13,14,15类别为B,16,17,18类别为C.
分析:一道大暴力,每次记录一下走了多少步,上一步操作类别是啥就可以了.最后只需要写6种操作,每一次操作进行4次就还原了,所以不用memcpy再来转.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n, ans[10], cnt, c[30]; bool stop = false; void turn1() { int tmp, tmp2; tmp = c[1]; c[1] = c[3]; c[3] = c[4]; c[4] = c[2]; c[2] = tmp; tmp = c[23]; tmp2 = c[24]; c[23] = c[10]; c[24] = c[9]; c[9] = c[5]; c[10] = c[6]; c[5] = c[13]; c[6] = c[14]; c[13] = tmp2; c[14] = tmp; } void turn2() { int tmp,tmp2; tmp = c[9]; c[9] = c[11]; c[11] = c[12]; c[12] = c[10]; c[10] = tmp; tmp = c[1]; tmp2 = c[3]; c[1] = c[21]; c[3] = c[23]; c[23] = c[19]; c[21] = c[17]; c[19] = c[7]; c[17] = c[5]; c[7] = tmp2; c[5] = tmp; } void turn3() { int tmp = c[5], tmp2; c[5] = c[7]; c[7] = c[8]; c[8] = c[6]; c[6] = tmp; tmp = c[17]; tmp2 = c[18]; c[17] = c[15]; c[18] = c[13]; c[15] = c[4]; c[13] = c[3]; c[3] = c[12]; c[4] = c[10]; c[10] = tmp; c[12] = tmp2; } void turn4() { int tmp = c[13], tmp2; c[13] = c[15]; c[15] = c[16]; c[16] = c[14]; c[14] = tmp; tmp = c[6]; tmp2 = c[8]; c[6] = c[18]; c[8] = c[20]; c[18] = c[22]; c[20] = c[24]; c[22] = c[2]; c[24] = c[4]; c[2] = tmp; c[4] = tmp2; } void turn5() { int tmp = c[21], tmp2; c[21] = c[23]; c[23] = c[24]; c[24] = c[22]; c[22] = tmp; tmp = c[19]; tmp2 = c[20]; c[19] = c[9]; c[20] = c[11]; c[9] = c[2]; c[11] = c[1]; c[1] = c[14]; c[2] = c[16]; c[14] = tmp2; c[16] = tmp; } void turn6() { int tmp = c[17], tmp2; c[17] = c[19]; c[19] = c[20]; c[20] = c[18]; c[18] = tmp; tmp = c[21]; tmp2 = c[22]; c[21] = c[16]; c[22] = c[15]; c[16] = c[8]; c[15] = c[7]; c[8] = c[12]; c[7] = c[11]; c[12] = tmp; c[11] = tmp2; } bool check() { return c[1] == c[2] && c[2] == c[3] && c[3] == c[4] && c[5] == c[6] && c[6] == c[7] && c[7] == c[8] && c[9] == c[10] && c[10] == c[11] && c[11] == c[12] && c[13] == c[14] && c[14] == c[15] && c[15] == c[16] && c[17] == c[18] && c[18] == c[19] && c[19] == c[20] && c[21] == c[22] && c[22] == c[23] && c[23] == c[24]; } void dfs(int dep, int flag) { if (check()) { cnt = dep; stop = 1; return; } if (dep >= n) return; if (flag != 1) { for (int i = 1; i <= 3; i++) { turn1(); ans[dep + 1] = i; dfs(dep + 1, 1); if (stop) return; } turn1(); } if (flag != 2) { for (int i = 1; i <= 3; i++) { turn2(); ans[dep + 1] = 3 + i; dfs(dep + 1, 2); if (stop) return; } turn2(); } if (flag != 3) { for (int i = 1; i <= 3; i++) { turn3(); ans[dep + 1] = 6 + i; dfs(dep + 1, 3); if (stop) return; } turn3(); } if (flag != 3) { for (int i = 1; i <= 3; i++) { turn4(); ans[dep + 1] = 9 + i; dfs(dep + 1, 3); if (stop) return; } turn4(); } if (flag != 2) { for (int i = 1; i <= 3; i++) { turn5(); ans[dep + 1] = 12 + i; dfs(dep + 1, 2); if (stop) return; } turn5(); } if (flag != 1) { for (int i = 1; i <= 3; i++) { turn6(); ans[dep + 1] = 15 + i; dfs(dep + 1, 1); if (stop) return; } turn6(); } } int main() { scanf("%d", &n); for (int i = 1; i <= 24; i++) scanf("%d", &c[i]); dfs(0, 0); for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]); return 0; }
标签:col names printf code scanf font mes emc memcpy
原文地址:http://www.cnblogs.com/zbtrs/p/7652008.html