Codeforces Round #444 (Div. 2) C. Solution for Cube

C. Solution for Cube

Problem Statement

    During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik’s cube 2x2x2.
    It’s too hard to learn to solve Rubik’s cube instantly, so she learns to understand if it’s possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
    To check her answers she wants to use a program which will for some state of cube tell if it’s possible to solve it using one rotation, described above.
    Cube is called solved if for each face of cube all squares on it has the same color.
    Cube

Input

    In first line given a sequence of 24 integers ai (1 ≤  ai  ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.

Output

    Print «YES» (without quotes) if it’s possible to solve cube using one rotation and «NO» (without quotes) otherwise.

Examples

Example 1
    Input
        2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
    Output
        NO
Example 2
    Input
        5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
    Output
        YES

Note

    这里写图片描述
    这里写图片描述

题意

    给你一个二阶魔方,求它是否能正好转一步90°使它还原。

思路

    这题没什么好说的,就是注意下细节和它折成一个立方体之后的哪一部分连哪一部分的样子就行了。

Code

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
typedef long long LL;
int a[7][5],b[7][5];
inline bool check() {
    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;
}
inline void copy_cube() {
    for(int i=1;i<=6;i++)
        for(int j=1;j<=4;j++)
            b[i][j]=a[i][j];
}
int main() {
    for(int j=1;j<=4;j++)
        scanf("%d",&a[1][j]);
    for(int j=1;j<=4;j++)
        scanf("%d",&a[2][j]);
    for(int j=1;j<=4;j++)
        scanf("%d",&a[3][j]);
    scanf("%d%d%d%d",&a[5][2],&a[5][4],&a[5][1],&a[5][3]);
    scanf("%d%d%d%d",&a[6][3],&a[6][1],&a[6][4],&a[6][2]);
    scanf("%d%d%d%d",&a[4][4],&a[4][3],&a[4][2],&a[4][1]);
    copy_cube();
    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(check()) {
        puts("YES");
        return 0;
    }
    copy_cube();
    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(check()) {
        puts("YES");
        return 0;
    }
    copy_cube();
    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(check()) {
        puts("YES");
        return 0;
    }
    copy_cube();
    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(check()) {
        puts("YES");
        return 0;
    }
    copy_cube();
    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(check()) {
        puts("YES");
        return 0;
    }
    copy_cube();
    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(check()){
        puts("YES");
        return 0;
    }
    puts("NO");
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值