首页 > 代码库 > HDU 5983 Pocket Cube
HDU 5983 Pocket Cube
Pocket Cube
Problem Description
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 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.
Input
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.
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 |
+ - + - +
Output
For each test case, output YES if can be restored in one step, otherwise output NO.
Sample Input
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
Sample Output
YES
YES
YES
NO
在给定的一个二阶魔方,是否在一次之内就还原,这题只能模拟,真变态。弄的我写了好多if。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 int a[7][5]; 6 bool check() { 7 for(int i = 0; i < 6; i ++) { 8 int ans = 0; 9 for(int j = 1; j < 4; j ++) { 10 if(a[i][j] == a[i][j-1]) ans++; 11 } 12 if(ans != 3) return false; 13 } 14 return true; 15 } 16 bool check1() { 17 if(!(a[0][0]==a[0][2]&&a[0][2]==a[3][1]&&a[3][1]==a[3][3]))return false; 18 if(!(a[1][0]==a[1][2]&&a[1][2]==a[0][1]&&a[0][1]==a[0][3]))return false; 19 if(!(a[2][0]==a[2][2]&&a[2][2]==a[1][1]&&a[1][1]==a[1][3]))return false; 20 if(!(a[3][0]==a[3][2]&&a[3][2]==a[2][1]&&a[2][1]==a[2][3]))return false; 21 if(!(a[4][0]==a[4][1]&&a[4][1]==a[4][2]&&a[4][2]==a[4][3]))return false; 22 if(!(a[5][0]==a[5][1]&&a[5][1]==a[5][2]&&a[5][2]==a[5][3]))return false; 23 return true; 24 } 25 bool check2() { 26 if(!(a[0][0]==a[0][2]&&a[0][2]==a[1][1]&&a[1][1]==a[1][3]))return false; 27 if(!(a[1][0]==a[1][2]&&a[1][2]==a[2][1]&&a[2][1]==a[2][3]))return false; 28 if(!(a[2][0]==a[2][2]&&a[2][2]==a[3][1]&&a[3][1]==a[3][3]))return false; 29 if(!(a[3][0]==a[3][2]&&a[3][2]==a[0][1]&&a[0][1]==a[0][3]))return false; 30 if(!(a[4][0]==a[4][1]&&a[4][1]==a[4][2]&&a[4][2]==a[4][3]))return false; 31 if(!(a[5][0]==a[5][1]&&a[5][1]==a[5][2]&&a[5][2]==a[5][3]))return false; 32 return true; 33 } 34 bool check3() { 35 if(!(a[0][0]==a[0][1]&&a[0][1]==a[0][2]&&a[0][2]==a[0][3]))return false; 36 if(!(a[2][0]==a[2][1]&&a[2][1]==a[2][2]&&a[2][2]==a[2][3]))return false; 37 if(!(a[1][0]==a[1][1]&&a[1][1]==a[5][1]&&a[5][1]==a[5][3]))return false; 38 if(!(a[5][0]==a[5][2]&&a[5][2]==a[3][0]&&a[3][0]==a[3][1]))return false; 39 if(!(a[3][2]==a[3][3]&&a[3][3]==a[4][0]&&a[4][0]==a[4][2]))return false; 40 if(!(a[4][1]==a[4][3]&&a[4][3]==a[1][2]&&a[1][2]==a[1][3]))return false; 41 return true; 42 } 43 bool check4() { 44 if(!(a[0][0]==a[0][1]&&a[0][1]==a[0][2]&&a[0][2]==a[0][3]))return false; 45 if(!(a[2][0]==a[2][1]&&a[2][1]==a[2][2]&&a[2][2]==a[2][3]))return false; 46 if(!(a[1][0]==a[1][1]&&a[1][1]==a[4][0]&&a[4][0]==a[4][2]))return false; 47 if(!(a[5][0]==a[5][2]&&a[5][2]==a[1][2]&&a[1][2]==a[1][3]))return false; 48 if(!(a[3][2]==a[3][3]&&a[3][3]==a[5][1]&&a[5][1]==a[5][3]))return false; 49 if(!(a[4][1]==a[4][3]&&a[4][3]==a[3][0]&&a[3][0]==a[3][1]))return false; 50 return true; 51 } 52 bool check5() { 53 if(!(a[1][0]==a[1][1]&&a[1][1]==a[1][2]&&a[1][2]==a[1][3]))return false; 54 if(!(a[3][0]==a[3][1]&&a[3][1]==a[3][2]&&a[3][2]==a[3][3]))return false; 55 if(!(a[0][0]==a[0][1]&&a[0][1]==a[5][2]&&a[5][2]==a[5][3]))return false; 56 if(!(a[5][0]==a[5][1]&&a[5][1]==a[2][0]&&a[2][0]==a[2][1]))return false; 57 if(!(a[2][2]==a[2][3]&&a[2][3]==a[4][2]&&a[4][2]==a[4][3]))return false; 58 if(!(a[4][0]==a[4][1]&&a[4][1]==a[0][2]&&a[0][2]==a[0][3]))return false; 59 return true; 60 } 61 bool check6() { 62 if(!(a[1][0]==a[1][1]&&a[1][1]==a[1][2]&&a[1][2]==a[1][3]))return false; 63 if(!(a[3][0]==a[3][1]&&a[3][1]==a[3][2]&&a[3][2]==a[3][3]))return false; 64 if(!(a[0][0]==a[0][1]&&a[0][1]==a[4][2]&&a[4][2]==a[4][3]))return false; 65 if(!(a[5][0]==a[5][1]&&a[5][1]==a[0][2]&&a[0][2]==a[0][3]))return false; 66 if(!(a[2][2]==a[2][3]&&a[2][3]==a[5][2]&&a[5][2]==a[5][3]))return false; 67 if(!(a[4][0]==a[4][1]&&a[4][1]==a[2][0]&&a[2][0]==a[2][1]))return false; 68 return true; 69 } 70 int main() { 71 int t; 72 cin >> t; 73 while(t--) { 74 memset(b,0,sizeof(b)); 75 for(int i = 0; i < 6; i ++) { 76 for(int j = 0; j < 4; j ++) { 77 scanf("%d", &a[i][j]); 78 b[a[i][j]]++; 79 } 80 } 81 if(check() || check1() || check2() || check3() || check4() || check5() || check6()) printf("YES\n"); 82 else printf("NO\n"); 83 } 84 return 0; 85 }
HDU 5983 Pocket Cube
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。