zoukankan      html  css  js  c++  java
  • 「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 #include<bits/stdc++.h>
      2 using namespace std;
      3 int a[10][10];
      4 bool f[10],f2[10];
      5 
      6 bool check(int a,int b,int c,int d)
      7 {
      8     if(a == b && c == d && a == c)
      9         return true;
     10     return false;
     11 }
     12 
     13 set<int> se;
     14 int main() 
     15 {
     16     int t;
     17     scanf("%d",&t);
     18     while(t--)
     19     {
     20         se.clear();
     21         memset(a,0,sizeof a);
     22         memset(f,0,sizeof f);
     23         memset(f2,0,sizeof f2);
     24         for(int i = 1;i <= 6;i++)
     25         {
     26             for(int j = 1;j <= 4;j++)
     27             {
     28                 scanf("%d",&a[i][j]);
     29             }
     30             int tmp = 1;
     31             for(int k = 2;k <= 4;k++)
     32             {
     33                 if(a[i][1] != a[i][k])
     34                     tmp = 0;
     35             }
     36             if(tmp == 1)
     37                 f[i] = 1;
     38         }
     39         int cou = 0;
     40         if(f[1] == 1 && f[3] == 1)
     41         {
     42             f2[1] = 1;
     43             cou++;
     44         }
     45         if(f[2] == 1 && f[4] == 1)
     46         {
     47             f2[2] = 1;
     48             cou++;
     49         }
     50         if(f[5] == 1 && f[6] == 1)
     51         {
     52             f2[3] = 1;
     53             cou++;
     54         }
     55         for(int i = 1;i <= 6;i++)
     56             for(int j = 1;j <= 4;j++)
     57                 se.insert(a[i][j]);
     58         int cas = se.size();
     59         if(cas != 6)
     60             cou = 0;
     61         if(cou == 2 || cou == 0)
     62         {
     63             printf("NO
    ");
     64         }
     65         else 
     66         {
     67             if(cou == 3)
     68             {
     69                 printf("YES
    ");
     70             }
     71             else 
     72             {
     73                 if(f2[1] == 1)
     74                 {
     75                     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])))
     76                         printf("YES
    ");
     77                     else 
     78                         printf("NO
    ");
     79                 }
     80                 else 
     81                 {
     82                     if(f2[2] == 1)
     83                     {
     84                         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])))
     85                            printf("YES
    ");
     86                         else 
     87                             printf("NO
    ");
     88                     }
     89                     else   // f2[3] == 1
     90                     {
     91                         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])))
     92                             printf("YES
    ");
     93                         else 
     94                             printf("NO
    ");
     95                     }
     96                        
     97                 }
     98             }
     99         }
    100         
    101     }
    102     return 0;
    103 }
  • 相关阅读:
    mybatis源码(三)SqlSession执行mapper的过程上篇
    Mybatis源码(二)mybatis核心组件介绍
    Mybatis源码(一) 之SqlSession的创建
    设计模式的分类及其六大设计原则
    设计模式之桥接模式
    设计模式之解释器模式
    设计模式之享元模式
    hdu3652
    Codeforces Round #703 (div2)
    Educational Codeforces Round 104
  • 原文地址:https://www.cnblogs.com/duny31030/p/14305115.html
Copyright © 2011-2022 走看看