zoukankan      html  css  js  c++  java
  • C

     
    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.

    题意:

    给一个二阶魔方,你看看你转一圈能不能还原它。 

    解题思路:

    开25的数组存输入的颜色(i=1开始);

    开[3][8]的数组分别存三种转的圈圈;

     

    对于三种圈圈 分别转两次(向前向后) 对于每次 都判断可不可还原;

    关于判断还原:

    对于每面,反应在25的数组上就是每4个元素,判断是否相同,有一不同则还原失败;

    关于旋转:

    最直接的体现就是,对于当前那一圈的所有涉及到的元素,向前或者向后挪两格。

    附上借鉴的代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int a[25],x[3][8]={{1,3,5,7,9,11,22,24},{13,14,5,6,17,18,21,22},{1,2,18,20,12,11,15,13}};
     5 void c() ///判断是否每一面都已经转好
     6 {
     7     for(int i=1;i<7;i++)
     8         for(int j=4*(i-1)+1;j<4*i;j++)
     9             if(a[j]!=a[4*i]) return ;
    10     puts("YES");exit(0);
    11 }
    12 
    13 
    14 void r(int i)
    15 {
    16     int v=a[x[i][0]],v2=a[x[i][1]];
    17 
    18     for(int j=0;j<6;j++)
    19         a[x[i][j]]=a[x[i][j+2]];
    20     a[x[i][6]]=v;
    21     a[x[i][7]]=v2;///向前转一次;
    22 
    23 }
    24 
    25 int main()
    26 {
    27     for(int i=1;i<25;i++)
    28         scanf("%d",&a[i]);
    29     for(int i=0;i<3;i++) ///对于每一种圈圈
    30         for(int k=0;k<2;k++)
    31     {
    32         ///转一次(k=0时,向前;k=1时,向后) 判断一下 在转一次(k=0为下一次转做准备,k=1,还原)
    33         r(i);c();r(i);
    34     }
    35     puts("NO");
    36     return 0;
    37 }
    C-Solution for Cube
    まだまだだね
  • 相关阅读:
    解决云服务器ECS,windows server 2012不能安装SQL Server 2012,不能安装.NET Fromework 3.5
    html5中checkbox的选中状态的设置与获取
    sql server 韩文查询匹配失败
    管理nuget程序包中搜索不到任何程序包
    ftp下出现“当前的安全设置不允许从该位置下载文件”提示
    windows server 2012 下IIS8.5关于“ 配置错误 不能在此路径中使用此配置节”的解决办法
    服务器升级后访问网站资源返回404
    centos7yum的更新与优化
    linux(centos7)命令提示符优化
    检查vmware虚拟软件服务是否开启?
  • 原文地址:https://www.cnblogs.com/xxQ-1999/p/7803590.html
Copyright © 2011-2022 走看看