2016年ICPC中国大陆区域赛(青岛)B题

题目网址点击进入

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.
在这里插入图片描述

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

大致题意:
这是一个二阶魔方,题目中给出魔方展开图,按照题目中字母顺序输入1-6的颜色序号,问是否可以在一步之内还原魔方

思路
憨批题一道,大模拟列举除了一开始就是六面同色之外的其余六种情况

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long int LLD;
LLD t,color[30];
bool zs()
{
    if  (((color[5]==color[2])&&(color[2]==color[4])&&(color[4]==color[7]))&&
        ((color[9]==color[6])&&(color[6]==color[8])&&(color[8]==color[11]))&&
        ((color[13]==color[10])&&(color[10]==color[12])&&(color[12]==color[15]))&&
        ((color[1]==color[14])&&(color[14]==color[16])&&(color[16]==color[3]))&&
        ((color[17]==color[18])&&(color[18]==color[20])&&(color[20]==color[19]))&&
        ((color[21]==color[22])&&(color[22]==color[24])&&(color[24]==color[23])))
        return true;
    else
        return false;
}
bool ys()
{
    if  (((color[1]==color[6])&&(color[6]==color[8])&&(color[8]==color[3]))&&
        ((color[5]==color[10])&&(color[10]==color[12])&&(color[12]==color[7]))&&
        ((color[9]==color[14])&&(color[14]==color[16])&&(color[16]==color[11]))&&
        ((color[13]==color[2])&&(color[2]==color[4])&&(color[4]==color[15]))&&
        ((color[17]==color[18])&&(color[18]==color[20])&&(color[20]==color[19]))&&
        ((color[21]==color[22])&&(color[22]==color[24])&&(color[24]==color[23])))
        return true;
    else
        return false;
}
bool hz()
{
    if  (((color[1]==color[2])&&(color[2]==color[20])&&(color[20]==color[19]))&&
        ((color[21]==color[22])&&(color[22]==color[4])&&(color[4]==color[3]))&&
        ((color[12]==color[11])&&(color[11]==color[24])&&(color[24]==color[23]))&&
        ((color[17]==color[18])&&(color[18]==color[9])&&(color[9]==color[10]))&&
        ((color[5]==color[6])&&(color[6]==color[8])&&(color[8]==color[7]))&&
        ((color[13]==color[14])&&(color[14]==color[16])&&(color[16]==color[15])))
        return true;
    else
        return false;
}
bool qz()
{
    if  (((color[17]==color[18])&&(color[18]==color[4])&&(color[4]==color[3]))&&
        ((color[1]==color[2])&&(color[2]==color[24])&&(color[24]==color[23]))&&
        ((color[21]==color[22])&&(color[22]==color[9])&&(color[9]==color[10]))&&
        ((color[12]==color[11])&&(color[11]==color[20])&&(color[20]==color[19]))&&
        ((color[5]==color[6])&&(color[6]==color[8])&&(color[8]==color[7]))&&
        ((color[13]==color[14])&&(color[14]==color[16])&&(color[16]==color[15])))
        return true;
    else
        return false;
}
bool sz()
{
    if  (((color[5]==color[6])&&(color[6]==color[22])&&(color[22]==color[24]))&&
        ((color[23]==color[21])&&(color[21]==color[13])&&(color[13]==color[14]))&&
        ((color[16]==color[15])&&(color[15]==color[19])&&(color[19]==color[17]))&&
        ((color[18]==color[20])&&(color[20]==color[8])&&(color[8]==color[7]))&&
        ((color[1]==color[2])&&(color[2]==color[4])&&(color[4]==color[3]))&&
        ((color[9]==color[10])&&(color[10]==color[12])&&(color[12]==color[11])))
        return true;
    else
        return false;
}
bool xz()
{
    if  (((color[5]==color[6])&&(color[6]==color[19])&&(color[19]==color[17]))&&
        ((color[23]==color[21])&&(color[21]==color[8])&&(color[8]==color[7]))&&
        ((color[16]==color[15])&&(color[15]==color[22])&&(color[22]==color[24]))&&
        ((color[18]==color[20])&&(color[20]==color[13])&&(color[13]==color[14]))&&
        ((color[1]==color[2])&&(color[2]==color[4])&&(color[4]==color[3]))&&
        ((color[9]==color[10])&&(color[10]==color[12])&&(color[12]==color[11])))
        return true;
    else
        return false;
}
int main()
{
    scanf("%lld",&t);
    while (t--)
    {
        LLD num=0;
        for (LLD i=1;i<=6;i++)
        {
            LLD flag=0;
            for (LLD j=1;j<=4;j++)
            {
                scanf("%lld",&color[(i-1)*4+j]);
                if (j!=1&&(color[(i-1)*4+j]==color[(i-1)*4+j-1]))
                {
                    flag++;
                }
            }
            if (flag==3)
            {
                num++;
            }
        }
        if (num==6)
        {
            printf("YES\n");
        }else
        {
            if (zs()||ys()||qz()||hz()||sz()||xz())
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}

发布了27 篇原创文章 · 获赞 4 · 访问量 4419

猜你喜欢

转载自blog.csdn.net/qq_43735840/article/details/104287980