「ACM Qingdao Onsite 2016」B.Pocket Cube(暴力 暴力 再暴力)

描述

传送门:我是传送门

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
+ - + - + - + - + - + - +
| 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

思路

直接暴力模拟,只有几种情况,分析一下就清楚了

但是有一个坑点:

必须判定是否有6种颜色出现

坑了我两个小时来debug

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
bool f[10],f2[10];

bool check(int a,int b,int c,int d)
{
if(a == b && c == d && a == c)
return true;
return false;
}

set<int> se;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
se.clear();
memset(a,0,sizeof a);
memset(f,0,sizeof f);
memset(f2,0,sizeof f2);
for(int i = 1;i <= 6;i++)
{
for(int j = 1;j <= 4;j++)
{
scanf("%d",&a[i][j]);
}
int tmp = 1;
for(int k = 2;k <= 4;k++)
{
if(a[i][1] != a[i][k])
tmp = 0;
}
if(tmp == 1)
f[i] = 1;
}
int cou = 0;
if(f[1] == 1 && f[3] == 1)
{
f2[1] = 1;
cou++;
}
if(f[2] == 1 && f[4] == 1)
{
f2[2] = 1;
cou++;
}
if(f[5] == 1 && f[6] == 1)
{
f2[3] = 1;
cou++;
}
for(int i = 1;i <= 6;i++)
for(int j = 1;j <= 4;j++)
se.insert(a[i][j]);
int cas = se.size();
if(cas != 6)
cou = 0;
if(cou == 2 || cou == 0)
{
printf("NO\n");
}
else
{
if(cou == 3)
{
printf("YES\n");
}
else
{
if(f2[1] == 1)
{
if((check(a[5][2],a[5][4],a[2][3],a[2][4]) && check(a[2][1],a[2][2],a[6][4],a[6][2]) && check(a[6][3],a[6][1],a[4][2],a[4][1]) && check(a[4][4],a[4][3],a[5][1],a[5][3])) || (check(a[5][2],a[5][4],a[4][2],a[4][1]) && check(a[2][1],a[2][2],a[5][1],a[5][3]) && check(a[6][3],a[6][1],a[2][3],a[2][4]) && check(a[4][4],a[4][3],a[6][4],a[6][2])))
printf("YES\n");
else
printf("NO\n");
}
else
{
if(f2[2] == 1)
{
if((check(a[5][1],a[5][2],a[1][3],a[1][4]) && check(a[1][1],a[1][2],a[6][3],a[6][4]) && check(a[6][1],a[6][2],a[3][2],a[3][1]) && check(a[3][4],a[3][3],a[5][3],a[5][4])) || (check(a[5][1],a[5][2],a[3][2],a[3][1]) && check(a[1][1],a[1][2],a[5][3],a[5][4]) && check(a[6][1],a[6][2],a[1][3],a[1][4]) && check(a[3][4],a[3][3],a[6][3],a[6][4])))
printf("YES\n");
else
printf("NO\n");
}
else // f2[3] == 1
{
if((check(a[1][1],a[1][3],a[2][2],a[2][4]) && check(a[2][1],a[2][3],a[3][2],a[3][4]) && check(a[3][1],a[3][3],a[4][2],a[4][4]) && check(a[4][1],a[4][3],a[1][2],a[1][4])) || (check(a[1][1],a[1][3],a[4][2],a[4][4]) && check(a[2][1],a[2][3],a[1][2],a[1][4]) && check(a[3][1],a[3][3],a[2][2],a[2][4]) && check(a[4][1],a[4][3],a[3][2],a[3][4])))
printf("YES\n");
else
printf("NO\n");
}

}
}
}

}
return 0;
}