【HDU 5983 Pocket Cube】& 模拟

本文介绍了一个关于PocketCube(2x2x2魔方)的问题,即如何判断一个打乱的PocketCube是否能够通过一步操作还原。文章详细描述了输入格式、输出要求,并提供了AC代码实现,包括六种旋转情况的模拟。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Pocket Cube

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

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亚洲区青岛站-重现赛(感谢中国石油大学)

题意 : 给以个 4 * 4 的阶的魔方,转动一次能否把所有的面都调为相同的颜色

思路 : 给出了魔方的输入的顺序,6 种情况模拟一下,注意转动过程种的对应

AC代码:

#include<cstdio>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
const int INF = 1e9 + 7;
typedef long long LL;
int a[7][5],b[7][5];
bool sf(){
    for(int i = 1; i <= 6; i++){
        for(int j = 2; j <= 4; j++)
            if(b[i][j] != b[i][j - 1])
                return false;
    }
    return true;
}
void fz(){
    for(int i = 1; i <= 6; i++)
        for(int j = 1; j <= 4; j++)
            b[i][j] = a[i][j];
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        for(int i = 1; i <= 6; i++)
            for(int j = 1; j <= 4; j++)
               scanf("%d",&a[i][j]);
        fz();
        if(sf()){
            puts("YES");
            continue;
        }
        int x = b[1][1],y = b[1][2];
        b[1][1] = b[6][1],b[1][2] = b[6][2];
        b[6][1] = b[3][4],b[6][2] = b[3][3];
        b[3][4] = b[5][1],b[3][3] = b[5][2];
        b[5][1] = x,b[5][2] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        fz();
        x = b[1][1],y = b[1][2];
        b[1][1] = b[5][1],b[1][2] = b[5][2];
        b[5][1] = b[3][4],b[5][2] = b[3][3];
        b[3][4] = b[6][1],b[3][3] = b[6][2];
        b[6][1] = x,b[6][2] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        fz();
        x = b[1][2],y = b[1][4];
        b[1][2] = b[4][2],b[1][4] = b[4][4];
        b[4][2] = b[3][2],b[4][4] = b[3][4];
        b[3][2] = b[2][2],b[3][4] = b[2][4];
        b[2][2] = x,b[2][4] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        fz();
        x = b[1][2],y = b[1][4];
        b[1][2] = b[2][2],b[1][4] = b[2][4];
        b[2][2] = b[3][2],b[2][4] = b[3][4];
        b[3][2] = b[4][2],b[3][4] = b[4][4];
        b[4][2] = x,b[4][4] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        fz();
        x = b[5][2],y = b[5][4];
        b[5][2] = b[2][1],b[5][4] = b[2][2];
        b[2][1] = b[6][3],b[2][2] = b[6][1];
        b[6][3] = b[4][4],b[6][1] = b[4][3];
        b[4][4] = x,b[4][3] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        fz();
        x = b[5][2],y = b[5][4];
        b[5][2] = b[4][4],b[5][4] = b[4][3];
        b[4][4] = b[6][3],b[4][3] = b[6][1];
        b[6][3] = b[2][1],b[6][1] = b[2][2];
        b[2][1] = x,b[2][2] = y;
        if(sf()){
            puts("YES");
            continue;
        }
        puts("NO");
     }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值