489

题目

The 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.

The 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 pieces
labelled 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 are
given 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 are
given 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 are
given 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 given
corresponding 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 given
corresponding 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 development
as 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 |
+ - + - +

For each test case, output YES if can be restored in one step, otherwise output NO.

4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6

YES
YES
YES
NO

题解

1种是初始情况就是还原的,另外对于每一面分别向两个方向转一次.

(一定要注意不要写错!!!)

代码

`cpp Pocket Cube https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
/*//
#define debug
#include
//*/
#include
#include
#include
#include
using namespace std;

int cube[24];

int list[7][24] = {
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23},
{0,5,2,7,4,9,6,11,8,13,10,15,12,1,14,3,16,17,18,19,22,20,23,21},
{0,13,2,15,4,1,6,3,8,5,10,7,12,9,14,11,16,17,18,19,21,23,20,22},
{20,21,2,3,4,5,6,7,8,9,16,17,12,13,14,15,0,1,18,19,10,11,22,23},
{16,17,2,3,4,5,6,7,8,9,20,21,12,13,14,15,10,11,18,19,0,1,22,23},
{2,0,3,1,22,20,6,7,8,9,10,11,12,13,19,17,16,4,18,5,14,21,15,23},
{1,3,0,2,17,19,6,7,8,9,10,11,12,13,20,22,16,15,18,14,4,21,5,23}
};

int check[24]={16,17,0,1,20,21,18,19,2,3,22,23,4,5,6,7,8,9,10,11,12,13,14,15};

map m;
void solve() {
m.clear();
int pos = 0;
int num[24];
memset(num, 0, sizeof(num));

for (int i = 0; i < 6; i++){
for (int j = 0; j < 4; j++) {
int t;
cin >> t;
cube[i * 4 + j] = t;
if (!m.count(t))
m.insert(make_pair(t, pos++));
num[m[t]]++;
}
}

// cout<<"Cube:"<// for(int i=0;i<24;i++)
// cout<// cout<
//必须是6种颜色,并且每种4个

bool ok = true;
for (int i = 0; i < 6 && ok; i++)
if (num[i] != 4)
ok = false;

if (ok) {
ok = false;

for (int i = 0; i < 7 && !ok; i++) {
//分别按照7种情况判断是否能够还原

// cout << "Case" << i << endl;
// for(int j=0;j<6;j++)
// printf("%3d",cube[list[i][check[j]]]);
// cout<// for(int j=6;j<12;j++)
// printf("%3d",cube[list[i][check[j]]]);
// cout<// for(int j=0;j<6;j++)
// printf(" %3d%3dn",cube[list[i][check[12+j2]]],cube[list[i][check[12+j2+1]]]);
// cout<

bool flag = true;
for (int j = 0; j < 6 && flag; j++) {
if (cube[list[i][4  j + 0]] != cube[list[i][4  j + 1]] ||
cube[list[i][4  j + 0]] != cube[list[i][4  j + 2]] ||
cube[list[i][4  j + 0]] != cube[list[i][4  j + 3]])
flag = false;
}
if (flag)
ok = true;
}
}
cout << (ok ? "YES" : "NO") << endl;
}

int main() {
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif

int T;
cin >> T;
while (T--)
solve();

#ifdef debug
printf("Time:%.3f s.n", double(clock() - START) / CLOCKSPERSEC);
#endif
return 0;
}

• 点击查看/关闭被识别为广告的评论