zoukankan      html  css  js  c++  java
  • codeforces C. Solution for Cube

    C. Solution for Cube

    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard 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.

    题意:一个立方体是2*2的。给出一种状态,判断是否可以只旋转90°就可以恢复原样。

    思路:暴力(被自己的方法蠢哭。。。)

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    int a[10][10];
    int b[10];
    int main()
    {
        int k=0;
        for(int i=1; i<=6; i++)
        {
            for(int j=1; j<=4; j++)
            {
                cin>>a[i][j];
            }
        }
        swap(a[6][1],a[6][2]);
        swap(a[6][3],a[6][4]);
        for(int i=1; i<=6; i++)
        {
            if(a[i][1]==a[i][2]&&a[i][1]==a[i][3]&&a[i][1]==a[i][4])
            {
                b[k++]=i;
            }
        }
        if(k!=2)
        {
            cout<<"NO"<<endl;
            return 0;
        }
        else
        {
            if(!((b[0]==1&&b[1]==3)||(b[0]==4&&b[1]==5)||(b[0]==2&&b[1]==6)))
            {
                cout<<"NO"<<endl;
                return 0;
            }
            if(b[0]==1&&b[1]==3)
            {
                for(int i=1; i<=6; i++)
                {
                    if(i!=1&&i!=3)
                    {
                        if(a[i][1]!=a[i][2]||a[i][3]!=a[i][4])
                        {
                            cout<<"NO"<<endl;
                            return 0;
                        }
                    }
                }
                if(a[2][1]==a[4][3]&&a[2][3]==a[5][1]&&a[5][3]==a[6][1]&&a[6][3]==a[4][1])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else if(a[2][1]==a[5][3]&&a[2][3]==a[4][1]&&a[4][3]==a[6][1]&&a[6][3]==a[5][1])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
            else if(b[0]==2&&b[1]==6)
            {
                for(int i=1; i<=6; i++)
                {
                    if(i!=2&&i!=6&&i!=4&&i!=5)
                    {
                        if(a[i][1]!=a[i][2]||a[i][3]!=a[i][4])
                        {
                            cout<<i<<"NO"<<endl;
                            return 0;
                        }
                    }
                    if(i==4||i==5)
                    {
                        if(a[i][1]!=a[i][3]||a[i][2]!=a[i][4])
                        {
                            cout<<"NO"<<endl;
                            return 0;
                        }
                    }
                }
                if(a[1][1]==a[5][3]&&a[3][1]==a[5][2]&&a[3][3]==a[4][4]&&a[1][3]==a[4][1])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else if(a[1][1]==a[4][2]&&a[3][1]==a[4][3]&&a[3][3]==a[5][3]&&a[1][3]==a[5][2])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
            else
            {
                for(int i=1; i<=6; i++)
                {
                    if(i!=4&&i!=5)
                    {
                        if(a[i][1]!=a[i][3]||a[i][2]!=a[i][4])
                        {
                            cout<<"NO"<<endl;
                            return 0;
                        }
                    }
                }
                if(a[1][1]==a[2][2]&&a[2][1]==a[3][2]&&a[3][1]==a[6][2]&&a[1][2]==a[6][1])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else if(a[1][2]==a[2][1]&&a[2][2]==a[3][1]&&a[3][2]==a[6][1]&&a[6][2]==a[1][1])
                {
                    cout<<"YES"<<endl;
                    return 0;
                }
                else
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
    
        }
    }
    







  • 相关阅读:
    COJ979 WZJ的数据结构(负二十一)
    COJ980 WZJ的数据结构(负二十)
    奇怪的错误
    COJ883 工艺品
    COJ885 LCS???
    COJ559 回文
    hdu1505(dp求最大子矩阵)
    hdu1506(dp求最大子矩阵)
    hdu2569(递推dp)
    hdu1081(最大子矩阵)
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053322.html
Copyright © 2011-2022 走看看