HDU 5983 Pocket Cube ICPC亚洲区青岛站(模拟)

来源:互联网 发布:淘宝电商差评怎么回复 编辑:程序博客网 时间:2024/04/30 17:05

Pocket Cube

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 198 Accepted Submission(s): 70

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.

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.

+ - + - + - + - + - + - +
| 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

Source
2016ACM/ICPC亚洲区青岛站-重现赛(感谢中国石油大学)

给出一个魔方,按照魔方的规则来玩儿。问给出的情况下,能否只操作一次就将魔方恢复好。暴力枚举六种情况就好了,难度主要在扭转后产生的新对应情况,各种标号比较容易弄错。

#include "cstring"#include "cstdio"#include "string.h"#include "iostream"#include "cmath"using namespace std;int com(int a,int b,int c,int d){    if(a==b&&b==c&&c==d) return 1;    else return 0;}int main(){   int cas;   int mark;   scanf("%d",&cas);   while(cas--)   {       mark=0;       int a[8][5];       int b[25];       int i,j;       for(int i=1;i<=6;i++)       {           for(j=1,b[i]=1;j<=4;j++)           {               scanf("%d",&a[i][j]);               if(j>=2)               {                   if(a[i][j]!=a[i][j-1])                        b[i]=0;               }           }       }       if(com(a[1][1],a[1][2],a[1][3],a[1][4])&&com(a[2][1],a[2][2],a[2][3],a[2][4])&&com(a[3][1],a[3][2],a[3][3],a[3][4])&&com(a[4][1],a[4][2],a[4][3],a[4][4])&&com(a[5][1],a[5][2],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[5][3],a[5][4])) mark=1;       if(b[1]&&b[3]&&com(a[2][1],a[2][2],a[5][1],a[5][3])&&com(a[6][1],a[6][3],a[2][3],a[2][4])&&com(a[5][2],a[5][4],a[4][1],a[4][2])&&com(a[4][3],a[4][4],a[6][4],a[6][2])) mark=1;       if(b[1]&&b[3]&&com(a[4][1],a[4][2],a[6][1],a[6][3])&&com(a[4][3],a[4][4],a[5][1],a[5][3])&&com(a[5][2],a[5][4],a[2][3],a[2][4])&&com(a[2][1],a[2][2],a[6][4],a[6][2])) mark=1;       if(b[5]&&b[6]&&com(a[1][2],a[1][4],a[2][1],a[2][3])&&com(a[2][2],a[2][4],a[3][1],a[3][3])&&com(a[3][2],a[3][4],a[4][3],a[4][1])&&com(a[4][4],a[4][2],a[1][3],a[1][1])) mark=1;       if(b[5]&&b[6]&&com(a[2][2],a[2][4],a[1][1],a[1][3])&&com(a[1][2],a[1][4],a[4][3],a[4][1])&&com(a[4][4],a[4][2],a[3][1],a[3][3])&&com(a[3][2],a[3][4],a[2][1],a[2][3])) mark=1;       if(b[2]&&b[4]&&com(a[1][1],a[1][2],a[6][3],a[6][4])&&com(a[6][1],a[6][2],a[3][1],a[3][2])&&com(a[3][3],a[3][4],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[1][3],a[1][4])) mark=1;       if(b[2]&&b[4]&&com(a[1][1],a[1][2],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[3][1],a[3][2])&&com(a[3][3],a[3][4],a[6][3],a[6][4])&&com(a[6][1],a[6][2],a[1][3],a[1][4])) mark=1;       if(mark)        printf("YES\n");       else        printf("NO\n");   }   return 0;}
0 0
原创粉丝点击