zoukankan      html  css  js  c++  java
  • ZOJ2477 Magic Cube

    题目:

    This is a very popular game for children. In this game, there's a cube, which consists of 3 * 3 * 3 small cubes. We can unwrap the cube, it will become like this:

          w w w
          w w w
          w w w
    r r r g g g b b b o o o
    r r r g g g b b b o o o
    r r r g g g b b b o o o
          y y y
          y y y
          y y y

    The letters means the color on the small cubes. For example, 'r' means red, 'g' means green, 'y' means yellow....The goal for this game is to rotate the faces of the cube to make each of the faces contains only one color. Note there're exact 6 kind of colors on the cube and there're exact 9 small rectangles totally in any time in the game.

    Do you know how to rotate the faces? I think most of you have known it. But I would like to show it again. When a face is rotated, the configuration of colors in all the adjacent faces changes. For the cube above, after we rotate the green face clock-wise, the last line of 'w' face will become the left column of 'b' face, the left column of 'b' face will become the top line of 'y' face, etc. As you may know, reaching the final position from a scrambled configuration can be quite challenging.

    In this problem, you are given a configuration of the cube, and asked to give a way to reach the final position. To reduce the difficulty, the steps required will never be greater than 5.

     输入:

    The input contains an integer in the first line, which indicates the number of the test cases. In each test case, there're exact 10 lines. The first line is an empty line. The next 9 lines contain a configuration. The format can be seen in the sample input. For simplicity, we give an index to each face as follows:

     

        /---
        |   |
        | 4 |
        |   |
    /---+---+---+---
    |   |   |   |   |
    | 0 | 1 | 2 | 3 |
    |   |   |   |   |
    ---+---+---+---/
        |   |
        | 5 |
        |   |
        ---/

    Note that there's a space between two adjacent letters.

     输出:

    For each test case, the first line of the output is the smallest count N of the steps to reach the winning position. If the winning position can't be reached in 5 steps, print -1 in this line. Otherwise print each step in one line in the following N lines. A step contains two integers, the first one means the face index, and the second one means the direction. 1 means clock-wise and -1 means counter clock-wise. If the given position is the winning position, print 0 for such test case simply. If there're multiple solutions, any one is acceptable.

    样例:

    分析:我。。。自闭了两天竟然是没有写>5输出-1(°ཀ°),为什么我会默认测试点必然可以在5步内实现啊(#`Д´)ノ

    只能说这个模拟太恶心了!!!

    用IDA*优化,思路是计算每一个面有几个和中心方格颜色不一样的方格,6个面的总数除12并向上取整是最少剩余需要的步数(如果最理想的情况加上已走步数仍然大于5那肯定没戏啊)

    模拟写得相当丑(灬ºωº灬)

      1 #include<iostream>
      2 #include<sstream>
      3 #include<cstdio>
      4 #include<cstdlib>
      5 #include<string>
      6 #include<cstring>
      7 #include<algorithm>
      8 #include<functional>
      9 #include<iomanip>
     10 #include<numeric>
     11 #include<cmath>
     12 #include<queue>
     13 #include<vector>
     14 #include<set>
     15 #include<cctype>
     16 #define PI acos(-1.0)
     17 const int INF = 0x3f3f3f3f;
     18 const int NINF = -INF - 1;
     19 typedef long long ll;
     20 using namespace std;
     21 char cube[10][25];
     22 struct node
     23 {
     24     char maze[3][3];
     25 };
     26 struct cur
     27 {
     28     char maze[10][25];
     29 };
     30 node clockwise(node temp)
     31 {
     32     char gtm[3][3];
     33     gtm[0][0] = temp.maze[2][0];
     34     gtm[0][1] = temp.maze[1][0];
     35     gtm[0][2] = temp.maze[0][0];
     36     gtm[1][0] = temp.maze[2][1];
     37     gtm[1][1] = temp.maze[1][1];
     38     gtm[1][2] = temp.maze[0][1];
     39     gtm[2][0] = temp.maze[2][2];
     40     gtm[2][1] = temp.maze[1][2];
     41     gtm[2][2] = temp.maze[0][2];
     42     memcpy(temp.maze, gtm, sizeof(temp.maze));
     43     return temp;
     44 }
     45 node cclockwise(node temp)
     46 {
     47     char gtm[3][3];
     48     gtm[0][0] = temp.maze[0][2];
     49     gtm[0][1] = temp.maze[1][2];
     50     gtm[0][2] = temp.maze[2][2];
     51     gtm[1][0] = temp.maze[0][1];
     52     gtm[1][1] = temp.maze[1][1];
     53     gtm[1][2] = temp.maze[2][1];
     54     gtm[2][0] = temp.maze[0][0];
     55     gtm[2][1] = temp.maze[1][0];
     56     gtm[2][2] = temp.maze[2][0];
     57     memcpy(temp.maze, gtm, sizeof(temp.maze));
     58     return temp;
     59 }
     60 int bol, ans;
     61 pair<int, int> P[5];
     62 void print()
     63 {
     64     for (int i = 0; i < ans; ++i)
     65         cout << P[i].first << ' ' << P[i].second << endl;
     66 }
     67 int hx(cur trans)
     68 {
     69     double sum = 0;
     70     for (int i = 3; i < 6; ++i)
     71     {
     72         for (int j = 0; j < 6; j += 2)
     73             if (trans.maze[i][j] != trans.maze[4][2]) sum++;
     74     }
     75     for (int i = 3; i < 6; ++i)
     76     {
     77         for (int j = 6; j < 11; j += 2)
     78             if (trans.maze[i][j] != trans.maze[4][8]) sum++;
     79     }
     80     for (int i = 3; i < 6; ++i)
     81     {
     82         for (int j = 12; j < 17; j += 2)
     83             if (trans.maze[i][j] != trans.maze[4][14]) sum++;
     84     }
     85     for (int i = 3; i < 6; ++i)
     86     {
     87         for (int j = 18; j < 23; j += 2)
     88             if (trans.maze[i][j] != trans.maze[4][20]) sum++;
     89     }
     90     for (int i = 0; i < 3; ++i)
     91     {
     92         for (int j = 6; j < 11; j += 2)
     93             if (trans.maze[i][j] != trans.maze[1][8]) sum++;
     94     }
     95     for (int i = 6; i < 9; ++i)
     96     {
     97         for (int j = 6; j < 11; j += 2)
     98             if (trans.maze[i][j] != trans.maze[7][8]) sum++;
     99     }
    100     return ceil(sum / 12);
    101 }
    102 void dfs(int rec, char pos[10][25], int deep)
    103 {
    104     if (rec > deep) return;
    105     cur trans;
    106     memcpy(trans.maze, pos, sizeof(trans.maze));
    107     int h = hx(trans);
    108     //cout << "test:" << h << endl;
    109     if (h == 0)
    110     {
    111         ans = rec;
    112         cout << rec << endl;
    113         bol = 1;
    114         return;
    115     }
    116     if (h + rec > deep) return;
    117     for (int i = 0; i < 12; ++i)
    118     {
    119         char tmp[10][25];
    120         memcpy(tmp, pos, sizeof(tmp));
    121         /*for (int j = 0; j < 9; ++j)
    122             cout << tmp[j] << endl;
    123         return;*/
    124         node temp;
    125         if (i == 0)
    126         {
    127             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    128             {
    129                 for (int j = 0, n = 0; j < 6, n < 3; j += 2, ++n)
    130                     temp.maze[m][n] = tmp[k][j];
    131             }
    132             temp = clockwise(temp);
    133             /*for (int m = 0; m < 3; ++m)
    134             {
    135                 for (int n = 0; n < 3; ++n)
    136                     cout << temp.maze[m][n] << ' ';
    137                 cout << endl;
    138             }*/
    139             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    140             {
    141                 for (int j = 0, n = 0; j < 6, n < 3; j += 2, ++n)
    142                     tmp[k][j] = temp.maze[m][n];
    143             }
    144             char cpy[10][25];
    145             memcpy(cpy, tmp, sizeof(cpy));
    146             cpy[0][6] = tmp[5][22];
    147             cpy[1][6] = tmp[4][22];
    148             cpy[2][6] = tmp[3][22];
    149             cpy[3][6] = tmp[0][6];
    150             cpy[4][6] = tmp[1][6];
    151             cpy[5][6] = tmp[2][6];
    152             cpy[6][6] = tmp[3][6];
    153             cpy[7][6] = tmp[4][6];
    154             cpy[8][6] = tmp[5][6];
    155             cpy[5][22] = tmp[6][6];
    156             cpy[4][22] = tmp[7][6];
    157             cpy[3][22] = tmp[8][6];
    158             memcpy(tmp, cpy, sizeof(tmp));
    159             /*for (int k = 0; k < 9; ++k)
    160                 cout << tmp[k] << endl;
    161             return;*/
    162         }
    163         else if (i == 1)
    164         {
    165             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    166             {
    167                 for (int j = 0, n = 0; j < 6, n < 3; j += 2, ++n)
    168                     temp.maze[m][n] = tmp[k][j];
    169             }
    170             temp = cclockwise(temp);
    171             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    172             {
    173                 for (int j = 0, n = 0; j < 6, n < 3; j += 2, ++n)
    174                     tmp[k][j] = temp.maze[m][n];
    175             }
    176             char cpy[10][25];
    177             memcpy(cpy, tmp, sizeof(cpy));
    178             cpy[0][6] = tmp[3][6];
    179             cpy[1][6] = tmp[4][6];
    180             cpy[2][6] = tmp[5][6];
    181             cpy[3][6] = tmp[6][6];
    182             cpy[4][6] = tmp[7][6];
    183             cpy[5][6] = tmp[8][6];
    184             cpy[6][6] = tmp[5][22];
    185             cpy[7][6] = tmp[4][22];
    186             cpy[8][6] = tmp[3][22];
    187             cpy[5][22] = tmp[0][6];
    188             cpy[4][22] = tmp[1][6];
    189             cpy[3][22] = tmp[2][6];
    190             memcpy(tmp, cpy, sizeof(tmp));
    191             /*for (int k = 0; k < 9; ++k)
    192                 cout << tmp[k] << endl;
    193             return;*/
    194         }
    195         else if (i == 2)
    196         {
    197             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    198             {
    199                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    200                     temp.maze[m][n] = tmp[k][j];
    201             }
    202             temp = clockwise(temp);
    203             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    204             {
    205                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    206                     tmp[k][j] = temp.maze[m][n];
    207             }
    208             char cpy[10][25];
    209             memcpy(cpy, tmp, sizeof(cpy));
    210             cpy[2][6] = tmp[5][4];
    211             cpy[2][8] = tmp[4][4];
    212             cpy[2][10] = tmp[3][4];
    213             cpy[3][12] = tmp[2][6];
    214             cpy[4][12] = tmp[2][8];
    215             cpy[5][12] = tmp[2][10];
    216             cpy[6][10] = tmp[3][12];
    217             cpy[6][8] = tmp[4][12];
    218             cpy[6][6] = tmp[5][12];
    219             cpy[3][4] = tmp[6][6];
    220             cpy[4][4] = tmp[6][8];
    221             cpy[5][4] = tmp[6][10];
    222             memcpy(tmp, cpy, sizeof(tmp));
    223             /*for (int k = 0; k < 9; ++k)
    224                 cout << tmp[k] << endl;
    225             return;*/
    226         }
    227         else if (i == 3)
    228         {
    229             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    230             {
    231                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    232                     temp.maze[m][n] = tmp[k][j];
    233             }
    234             temp = cclockwise(temp);
    235             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    236             {
    237                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    238                     tmp[k][j] = temp.maze[m][n];
    239             }
    240             char cpy[10][25];
    241             memcpy(cpy, tmp, sizeof(cpy));
    242             cpy[5][4] = tmp[2][6];
    243             cpy[4][4] = tmp[2][8];
    244             cpy[3][4] = tmp[2][10];
    245             cpy[2][6] = tmp[3][12];
    246             cpy[2][8] = tmp[4][12];
    247             cpy[2][10] = tmp[5][12];
    248             cpy[3][12] = tmp[6][10];
    249             cpy[4][12] = tmp[6][8];
    250             cpy[5][12] = tmp[6][6];
    251             cpy[6][6] = tmp[3][4];
    252             cpy[6][8] = tmp[4][4];
    253             cpy[6][10] = tmp[5][4];
    254             memcpy(tmp, cpy, sizeof(tmp));
    255             /*for (int k = 0; k < 9; ++k)
    256                 cout << tmp[k] << endl;
    257             return;*/
    258         }
    259         else if (i == 4)
    260         {
    261             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    262             {
    263                 for (int j = 12, n = 0; j < 17, n < 3; j += 2, ++n)
    264                     temp.maze[m][n] = tmp[k][j];
    265             }
    266             temp = clockwise(temp);
    267             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    268             {
    269                 for (int j = 12, n = 0; j < 17, n < 3; j += 2, ++n)
    270                     tmp[k][j] = temp.maze[m][n];
    271             }
    272             char cpy[10][25];
    273             memcpy(cpy, tmp, sizeof(cpy));
    274             cpy[2][10] = tmp[5][10];
    275             cpy[1][10] = tmp[4][10];
    276             cpy[0][10] = tmp[3][10];
    277             cpy[3][18] = tmp[2][10];
    278             cpy[4][18] = tmp[1][10];
    279             cpy[5][18] = tmp[0][10];
    280             cpy[6][10] = tmp[5][18];
    281             cpy[7][10] = tmp[4][18];
    282             cpy[8][10] = tmp[3][18];
    283             cpy[3][10] = tmp[6][10];
    284             cpy[4][10] = tmp[7][10];
    285             cpy[5][10] = tmp[8][10];
    286             memcpy(tmp, cpy, sizeof(tmp));
    287             /*for (int k = 0; k < 9; ++k)
    288                 cout << tmp[k] << endl;
    289             return;*/
    290         }
    291         else if (i == 5)
    292         {
    293             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    294             {
    295                 for (int j = 12, n = 0; j < 17, n < 3; j += 2, ++n)
    296                     temp.maze[m][n] = tmp[k][j];
    297             }
    298             temp = cclockwise(temp);
    299             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    300             {
    301                 for (int j = 12, n = 0; j < 17, n < 3; j += 2, ++n)
    302                     tmp[k][j] = temp.maze[m][n];
    303             }
    304             char cpy[10][25];
    305             memcpy(cpy, tmp, sizeof(cpy));
    306             cpy[5][10] = tmp[2][10];
    307             cpy[4][10] = tmp[1][10];
    308             cpy[3][10] = tmp[0][10];
    309             cpy[2][10] = tmp[3][18];
    310             cpy[1][10] = tmp[4][18];
    311             cpy[0][10] = tmp[5][18];
    312             cpy[5][18] = tmp[6][10];
    313             cpy[4][18] = tmp[7][10];
    314             cpy[3][18] = tmp[8][10];
    315             cpy[6][10] = tmp[3][10];
    316             cpy[7][10] = tmp[4][10];
    317             cpy[8][10] = tmp[5][10];
    318             memcpy(tmp, cpy, sizeof(tmp));
    319             /*for (int k = 0; k < 9; ++k)
    320                 cout << tmp[k] << endl;
    321             return;*/
    322         }
    323         else if (i == 6)
    324         {
    325             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    326             {
    327                 for (int j = 18, n = 0; j < 23, n < 3; j += 2, ++n)
    328                     temp.maze[m][n] = tmp[k][j];
    329             }
    330             temp = clockwise(temp);
    331             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    332             {
    333                 for (int j = 18, n = 0; j < 23, n < 3; j += 2, ++n)
    334                     tmp[k][j] = temp.maze[m][n];
    335             }
    336             char cpy[10][25];
    337             memcpy(cpy, tmp, sizeof(cpy));
    338             cpy[0][10] = tmp[5][16];
    339             cpy[0][8] = tmp[4][16];
    340             cpy[0][6] = tmp[3][16];
    341             cpy[3][0] = tmp[0][10];
    342             cpy[4][0] = tmp[0][8];
    343             cpy[5][0] = tmp[0][6];
    344             cpy[8][10] = tmp[5][0];
    345             cpy[8][8] = tmp[4][0];
    346             cpy[8][6] = tmp[3][0];
    347             cpy[3][16] = tmp[8][10];
    348             cpy[4][16] = tmp[8][8];
    349             cpy[5][16] = tmp[8][6];
    350             memcpy(tmp, cpy, sizeof(tmp));
    351             /*for (int k = 0; k < 9; ++k)
    352                 cout << tmp[k] << endl;
    353             return;*/
    354         }
    355         else if (i == 7)
    356         {
    357             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    358             {
    359                 for (int j = 18, n = 0; j < 23, n < 3; j += 2, ++n)
    360                     temp.maze[m][n] = tmp[k][j];
    361             }
    362             temp = cclockwise(temp);
    363             for (int k = 3, m = 0; k < 6, m < 3; ++k, ++m)
    364             {
    365                 for (int j = 18, n = 0; j < 23, n < 3; j += 2, ++n)
    366                     tmp[k][j] = temp.maze[m][n];
    367             }
    368             char cpy[10][25];
    369             memcpy(cpy, tmp, sizeof(cpy));
    370             cpy[5][16] = tmp[0][10];
    371             cpy[4][16] = tmp[0][8];
    372             cpy[3][16] = tmp[0][6];
    373             cpy[0][10] = tmp[3][0];
    374             cpy[0][8] = tmp[4][0];
    375             cpy[0][6] = tmp[5][0];
    376             cpy[5][0] = tmp[8][10];
    377             cpy[4][0] = tmp[8][8];
    378             cpy[3][0] = tmp[8][6];
    379             cpy[8][10] = tmp[3][16];
    380             cpy[8][8] = tmp[4][16];
    381             cpy[8][6] = tmp[5][16];
    382             memcpy(tmp, cpy, sizeof(tmp));
    383             /*for (int k = 0; k < 9; ++k)
    384                 cout << tmp[k] << endl;
    385             return;*/
    386         }
    387         else if (i == 8)
    388         {
    389             for (int k = 0, m = 0; k < 3, m < 3; ++k, ++m)
    390             {
    391                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    392                     temp.maze[m][n] = tmp[k][j];
    393             }
    394             temp = clockwise(temp);
    395             for (int k = 0, m = 0; k < 3, m < 3; ++k, ++m)
    396             {
    397                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    398                     tmp[k][j] = temp.maze[m][n];
    399             }
    400             char cpy[10][25];
    401             memcpy(cpy, tmp, sizeof(cpy));
    402             cpy[3][22] = tmp[3][4];
    403             cpy[3][20] = tmp[3][2];
    404             cpy[3][18] = tmp[3][0];
    405             cpy[3][16] = tmp[3][22];
    406             cpy[3][14] = tmp[3][20];
    407             cpy[3][12] = tmp[3][18];
    408             cpy[3][6] = tmp[3][12];
    409             cpy[3][8] = tmp[3][14];
    410             cpy[3][10] = tmp[3][16];
    411             cpy[3][0] = tmp[3][6];
    412             cpy[3][2] = tmp[3][8];
    413             cpy[3][4] = tmp[3][10];
    414             memcpy(tmp, cpy, sizeof(tmp));
    415             /*for (int k = 0; k < 9; ++k)
    416                 cout << tmp[k] << endl;
    417             return;*/
    418         }
    419         else if (i == 9)
    420         {
    421             for (int k = 0, m = 0; k < 3, m < 3; ++k, ++m)
    422             {
    423                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    424                     temp.maze[m][n] = tmp[k][j];
    425             }
    426             temp = cclockwise(temp);
    427             for (int k = 0, m = 0; k < 3, m < 3; ++k, ++m)
    428             {
    429                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    430                     tmp[k][j] = temp.maze[m][n];
    431             }
    432             char cpy[10][25];
    433             memcpy(cpy, tmp, sizeof(cpy));
    434             cpy[3][4] = tmp[3][22];
    435             cpy[3][2] = tmp[3][20];
    436             cpy[3][0] = tmp[3][18];
    437             cpy[3][22] = tmp[3][16];
    438             cpy[3][20] = tmp[3][14];
    439             cpy[3][18] = tmp[3][12];
    440             cpy[3][12] = tmp[3][6];
    441             cpy[3][14] = tmp[3][8];
    442             cpy[3][16] = tmp[3][10];
    443             cpy[3][6] = tmp[3][0];
    444             cpy[3][8] = tmp[3][2];
    445             cpy[3][10] = tmp[3][4];
    446             memcpy(tmp, cpy, sizeof(tmp));
    447             /*for (int k = 0; k < 9; ++k)
    448                 cout << tmp[k] << endl;
    449             return;*/
    450         }
    451         else if (i == 10)
    452         {
    453             for (int k = 6, m = 0; k < 9, m < 3; ++k, ++m)
    454             {
    455                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    456                     temp.maze[m][n] = tmp[k][j];
    457             }
    458             temp = clockwise(temp);
    459             for (int k = 6, m = 0; k < 9, m < 3; ++k, ++m)
    460             {
    461                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    462                     tmp[k][j] = temp.maze[m][n];
    463             }
    464             char cpy[10][25];
    465             memcpy(cpy, tmp, sizeof(cpy));
    466             cpy[5][6] = tmp[5][0];
    467             cpy[5][8] = tmp[5][2];
    468             cpy[5][10] = tmp[5][4];
    469             cpy[5][12] = tmp[5][6];
    470             cpy[5][14] = tmp[5][8];
    471             cpy[5][16] = tmp[5][10];
    472             cpy[5][18] = tmp[5][12];
    473             cpy[5][20] = tmp[5][14];
    474             cpy[5][22] = tmp[5][16];
    475             cpy[5][4] = tmp[5][22];
    476             cpy[5][2] = tmp[5][20];
    477             cpy[5][0] = tmp[5][18];
    478             memcpy(tmp, cpy, sizeof(tmp));
    479             /*for (int k = 0; k < 9; ++k)
    480                 cout << tmp[k] << endl;
    481             return;*/
    482         }
    483         else if (i == 11)
    484         {
    485             for (int k = 6, m = 0; k < 9, m < 3; ++k, ++m)
    486             {
    487                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    488                     temp.maze[m][n] = tmp[k][j];
    489             }
    490             temp = cclockwise(temp);
    491             for (int k = 6, m = 0; k < 9, m < 3; ++k, ++m)
    492             {
    493                 for (int j = 6, n = 0; j < 11, n < 3; j += 2, ++n)
    494                     tmp[k][j] = temp.maze[m][n];
    495             }
    496             char cpy[10][25];
    497             memcpy(cpy, tmp, sizeof(cpy));
    498             cpy[5][0] = tmp[5][6];
    499             cpy[5][2] = tmp[5][8];
    500             cpy[5][4] = tmp[5][10];
    501             cpy[5][6] = tmp[5][12];
    502             cpy[5][8] = tmp[5][14];
    503             cpy[5][10] = tmp[5][16];
    504             cpy[5][12] = tmp[5][18];
    505             cpy[5][14] = tmp[5][20];
    506             cpy[5][16] = tmp[5][22];
    507             cpy[5][22] = tmp[5][4];
    508             cpy[5][20] = tmp[5][2];
    509             cpy[5][18] = tmp[5][0];
    510             memcpy(tmp, cpy, sizeof(tmp));
    511             /*for (int k = 0; k < 9; ++k)
    512                 cout << tmp[k] << endl;
    513             return;*/
    514         }
    515         /*if (i == 1 && deep == 2)
    516         {
    517             cout << "first" << endl;
    518             for (int k = 0; k < 9; ++k)
    519                 cout << tmp[k] << endl;
    520         }
    521         if (i == 2 && deep == 2)
    522         {
    523             cout << "second" << endl;
    524             for (int k = 0; k < 9; ++k)
    525                 cout << tmp[k] << endl;
    526         }*/
    527         dfs(rec + 1, tmp, deep);
    528         //if (i == 1) return;
    529         if (bol)
    530         {
    531             P[rec].first = i / 2;
    532             if (i % 2 == 0) P[rec].second = 1;
    533             else P[rec].second = -1;
    534             return;
    535         }
    536     }
    537 }
    538 int main()
    539 {
    540     int T;
    541     cin >> T;
    542     while (T--)
    543     {
    544         string nul;
    545         getline(cin, nul);
    546         for (int i = 0; i < 9; ++i)
    547         {
    548             char ss;
    549             int num = 0;
    550             while ((ss = getchar()) != '
    ')
    551             {
    552                 if (ss != ' ') cube[i][num++] = ss;
    553                 else cube[i][num++] = ' ';
    554             }
    555             cube[i][num] = '';
    556         }
    557         /*for (int i = 0; i < 9; ++i)
    558             cout << cube[i] << endl;*/
    559         /*for (int i = 0; i < 3; ++i)
    560         {
    561             for (int j = 6; j < 11; j += 2)
    562             {
    563                 cout << cube[i][j] << ' ';
    564             }
    565             cout << endl;
    566         }*/
    567         /*cur gat;
    568         memcpy(gat.maze, cube, sizeof(gat.maze));
    569         int p = judge(gat);
    570         cout << p << endl;*/
    571         bol = 0, ans = 0;
    572         for (int i = 1; i <= 5; ++i)
    573         {
    574             //cout << "deep:" <<  i << endl;
    575             dfs(0, cube, i);
    576             if (bol)
    577             {
    578                 print();
    579                 break;
    580             }
    581         }
    582         if (!bol) cout << -1 << endl;
    583     }
    584     return 0;
    585 }
  • 相关阅读:
    跳跃游戏
    不同路径
    最大子序和
    最长回文子序列
    最长公共子序列
    零钱兑换
    合并区间
    寻找数组的中心索引
    制造小程序中的一些经验
    h5写的一个签到积分系统
  • 原文地址:https://www.cnblogs.com/veasky/p/11058943.html
Copyright © 2011-2022 走看看