大体题意:
给你一个2*2*2的魔方,问你能否一步到达各个面的颜色完全一样。
思路:
其实挺简单的,题意已经给足了提示,已经告诉你了魔方怎么进行标号。(就是那个图)
只要给魔方标号,怎么转就很简单了,可以预处理一个b 数组和c 数组,分别是魔方转一个面时候的侧面的八个面和上面的四个面,循环赋值即可。
这样 写好循环赋值函数后,转六个面只需要更改b数组和c数组即可。
详细见代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[25];bool ok;int ori[25];void fuyuan(){ for (int i = 0; i < 24; ++i) a[i] = ori[i];}bool check(){ for (int i = 0; i < 24; i += 4){ for (int j = i; j < i+4; ++j){ if (a[j] != a[i]) return false; } } return true;}int b[] = {14,15,20,22,5,4,19,17};int c[] = {2,3,1,0};void zhuan(){ int t1 = a[b[0]], t2 = a[b[1]]; for (int i = 0; i < 6; i += 2){ int id1 = b[i], id2 = b[i+1]; int nid1 = b[i+2], nid2 = b[i+3]; a[id1] = a[nid1]; a[id2] = a[nid2]; } a[b[6] ] = t1; a[b[7] ] = t2; if (check()) ok = 1;fuyuan(); t1 = a[b[7]], t2 = a[b[6]]; for (int i = 7; i > 2; i -= 2){ int id1 = b[i], id2 = b[i-1]; int nid1 = b[i-2], nid2 = b[i-3]; a[id1] = a[nid1]; a[id2] = a[nid2]; } a[b[0] ] = t2; a[b[1] ] = t1; if (check()) ok = 1; fuyuan();}void add(int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int c0,int c1,int c2,int c3){ b[0] = a0;b[1] = a1;b[2] = a2;b[3] = a3;b[4] = a4;b[5] = a5;b[6] = a6;b[7] = a7; c[0] = c0;c[1] = c1;c[2] = c2;c[3] = c3;}void up(){ add(14,15,20,22,5,4,19,17,2,3,1,0); zhuan();}void down(){ add(12,13,21,23,7,6,18,16,8,9,11,10); zhuan();}void Left(){ add(2,0,14,12,10,8,6,4,19,17,18,16); zhuan();}void Right(){ add(3,1,15,13,11,9,7,5,20,22,23,21); zhuan();}void qian(){ add(0,1,20,21,11,10,16,17,14,15,13,12); zhuan();}void hou(){ add(2,3,22,23,9,8,18,19,4,5,6,7); zhuan();}int main(){ int T; scanf("%d",&T); while(T--){ ok = 0; for (int i = 0; i < 24; ++i) scanf("%d",a+i); for (int i = 0; i < 24; ++i)ori[i] = a[i]; if (check()) ok = 1; up(); down(); Left(); Right(); qian(); hou(); if (ok)puts("YES"); else puts("NO"); } return 0;}Pocket Cube
Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 358 Accepted Submission(s): 131PRoblem DescriptionThe Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube.The cube consists of 8 pieces, all corners.Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer.For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise.You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers. InputThe first line of input contains one integer N(N ≤ 30) which is the number of test cases.For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieceslabelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces.The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers aregiven corresponding to the above pieces.The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers aregiven corresponding to the above pieces.The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers aregiven corresponding to the above pieces.The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are givencorresponding to the above pieces.The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are givencorresponding to the above pieces.In other Words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface developmentas follows.+ - + - + - + - + - + - +| q | r | a | b | u | v |+ - + - + - + - + - + - +| s | t | c | d | w | x |+ - + - + - + - + - + - + | e | f | + - + - + | g | h | + - + - + | i | j | + - + - + | k | l | + - + - + | m | n | + - + - + | o | p | + - + - + OutputFor each test case, output YES if can be restored in one step, otherwise output NO. Sample Input41 1 1 12 2 2 23 3 3 34 4 4 45 5 5 56 6 6 66 6 6 61 1 1 12 2 2 23 3 3 35 5 5 54 4 4 41 4 1 42 1 2 13 2 3 24 3 4 35 5 5 56 6 6 61 3 1 32 4 2 43 1 3 14 2 4 25 5 5 56 6 6 6 Sample OutputYESYESYESNO Source2016ACM/ICPC亚洲区青岛站-重现赛(感谢中国石油大学) Recommendjiangzijing2015 | We have carefully selected several similar problems for you: 6014 6013 6012 6011 6010
新闻热点
疑难解答