Codeforces Round #444 (Div. 2) C. Solution for Cube 枚举模拟魔方

Posted ProLightsfxjh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #444 (Div. 2) C. Solution for Cube 枚举模拟魔方相关的知识,希望对你有一定的参考价值。

C. Solution for Cube time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

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.

https://en.wikipedia.org/wiki/Rubik's_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 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
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

In first test case cube looks like this:

In second test case cube looks like this:

It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.


Source

Codeforces Round #444 (Div. 2)

My Solution

题意:给出一个2*2*2的魔方的一个状态,问能不能转一下使得魔方满足每个面只有同一种颜色(1<= ai <= 6)。

枚举、模拟、魔方

根据题意只有2个面已经是同一种颜色,另外4个面每个面2种颜色,才可能可行可能可行。

每个面按以下方式编号,

    1

4  2  5  6 

    3

则根据相同的面是1与3或者2与6或者4与5进行讨论。

然后对于每种情况讨论转的方向(顺时针或者逆时针),耐心的慢慢写,慢慢模拟就行。

详情请见代码。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 8;

int v[8][2][2];
bool f[8];

int main()

    #ifdef LOCAL
    freopen("c.txt", "r", stdin);
    //freopen("c.out", "w", stdout);
    int T = 4;
    while(T--)
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    bool ans = false;
    int i, j, k, cnt, lf = -1, rf = -1;
    for(i = 1; i <= 6; i++)
        cnt = 0;
        for(j = 0; j < 2; j++)
            for(k = 0; k < 2; k++)
                cin >> v[i][j][k];
                if(v[i][j][k] == v[i][0][0])
                    cnt++;
                
            
        
        if(cnt == 4)
            f[i] = true;
        
    
    cnt = 0;
    for(i = 1; i <= 6; i++)
        if(f[i])
            cnt++;
            if(lf == -1)
                lf = i;
            
            else rf = i;
        
    
    if(cnt == 2)
        if(lf == 1 && rf == 3)
            if(v[2][0][0] == v[2][0][1] && v[2][1][0] == v[2][1][1] && v[5][0][0] == v[5][0][1] && v[5][1][0] == v[5][1][1] &&
            v[6][0][0] == v[6][0][1] && v[6][1][0] == v[6][1][1] && v[4][0][0] == v[4][0][1] && v[4][1][0] == v[4][1][1])
                if(v[2][0][0] == v[5][1][0] && v[5][0][0] == v[6][1][0] && v[6][0][0] == v[4][1][0] && v[4][0][0] == v[2][1][0])
                    ans = true;
                
                if(v[2][0][0] == v[4][1][0] && v[4][0][0] == v[6][1][0] && v[6][0][0] == v[5][1][0] && v[5][0][0] == v[2][1][0])
                    ans = true;
                
            
        
        else if(lf == 2 && rf == 6)
            if(v[1][0][0] == v[1][0][1] && v[1][1][0] == v[1][1][1] && v[3][0][0] == v[3][0][1] && v[3][1][0] == v[3][1][1] &&
               v[5][0][0] == v[5][1][0] && v[5][0][1] == v[5][1][1]  && v[4][0][0] == v[4][1][0] && v[4][0][1] == v[4][1][1])
                if(v[1][0][0] == v[5][0][0] && v[5][0][1] == v[3][0][0] && v[3][1][0] == v[4][0][1] && v[4][0][0] == v[1][1][0])
                    ans = true;
                
                if(v[1][0][0] == v[4][0][1] && v[4][0][0] == v[3][0][0] && v[3][1][0] == v[5][0][0] && v[5][0][1] == v[1][1][0])
                    ans = true;
                
            
        
        else if(lf == 4 && rf == 5)
            if(v[1][0][0] == v[1][1][0] && v[1][0][1] == v[1][1][1] && v[3][0][0] == v[3][1][0] && v[3][0][1] == v[3][1][1] &&
               v[2][0][0] == v[2][1][0] && v[2][0][1] == v[2][1][1]  && v[6][0][0] == v[6][1][0] && v[6][0][1] == v[6][1][1])

                if(v[1][0][0] == v[2][0][1] && v[2][0][0] == v[3][0][1] && v[3][0][0] == v[6][0][0] && v[6][0][1] == v[1][0][1])
                    ans = true;
                
                if(v[1][0][0] == v[6][0][0] && v[2][0][0] == v[1][0][1] && v[3][0][0] == v[2][0][1] && v[6][0][1] == v[3][0][1])
                    ans = true;
                
            
        
    

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;



    #ifdef LOCAL
    memset(f, false, sizeof f);
    cout << endl;
    
    #endif // LOCAL
    return 0;

  Thank you!

                                                                                                                                             ------from ProLights

以上是关于Codeforces Round #444 (Div. 2) C. Solution for Cube 枚举模拟魔方的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #444 (Div. 2) B. Cubes for Masha 暴力枚举

Codeforces Round #436 E. Fire(背包dp+输出路径)

Educational Codeforces Round 131 div.2 A-F题解

Educational Codeforces Round 131 div.2 A-F题解

[ACM]Codeforces Round #534 (Div. 2)

Educational Codeforces Round 110 div.2 A~F题解