zoukankan      html  css  js  c++  java
  • HDU 5983(模拟魔方 模拟)

    题意是说给定一个 2*2 魔方的各个面的情况,问是否能转动不超过一次使得魔方复原。

    思路是先在输入的时候统计一下已完成的面数,要想以最多一次的转动使得魔方复原,那么已完成的面数只能是 2 面或者 6 面,此处可剪枝。

    若已完成 6 面,那么一定可以复原;

    若已完成 2 面,则要用一次转动完成其他六面,开始这里打算用结构体去存,结果在判断的时候自己混乱了……最终直接定了 24 个变量,a,b,c……w,x,

    手动做了个小正方体,太丢人……(但不得不说这种方法挺好的,易于理解,而且不会乱^_^)

    代码如下:

      1 #include <bits/stdc++.h>
      2 using namespace std;
      3 int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;
      4 bool xu[8];
      5 int main()
      6 {
      7     int times,cnt;
      8     bool wu;
      9     scanf("%d",&times);
     10     while(times--)
     11     {
     12         cnt = 0;
     13         memset(xu,0,sizeof(xu));
     14         scanf("%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j,&k,&l,&m,&n,&o,&p,&q,&r,&s,&t,&u,&v,&w,&x);
     15         if(a==b&&b==c&&c==d)
     16         {
     17             ++cnt;
     18             xu[0] = 1;
     19         }
     20         if(e==f&&f==g&&g==h)
     21         {
     22             ++cnt;
     23             xu[1] = 1;
     24         }
     25         if(i==j&&j==k&&k==l)
     26         {
     27             ++cnt;
     28             xu[2] = 1;
     29         }
     30         if(m==n&&n==o&&o==p)
     31         {
     32             ++cnt;
     33             xu[3] = 1;
     34         }
     35         if(q==r&&r==s&&s==t)
     36         {
     37             ++cnt;
     38             xu[4] = 1;
     39         }
     40         if(u==v&&v==w&&w==x)
     41         {
     42             ++cnt;
     43             xu[5] = 1;
     44         }
     45         if(cnt==6) puts("YES");
     46         else if(cnt==2)
     47         {
     48             wu = 0;
     49             if(xu[0]&&xu[2])
     50             {
     51                 if(m==n&&m==u&&m==w)
     52                 {
     53                     if(v==x&&v==e&&v==f)
     54                         if(g==h&&g==r&&g==t)
     55                             if(q==s&&q==o&&q==p)
     56                                 wu = 1;
     57                 }
     58                 else if(m==n&&m==r&&m==t)
     59                 {
     60                     if(q==s&&q==e&&q==f)
     61                         if(g==h&&g==u&&g==w)
     62                             if(v==x&&v==o&&v==p)
     63                                 wu = 1;
     64                 }
     65             }
     66             else if(xu[1] && xu[3])
     67             {
     68                 if(a==b&&a==w&&a==x)
     69                 {
     70                     if(u==v&&u==i&&u==j)
     71                         if(k==l&&k==s&&k==t)
     72                             if(q==r&&q==c&&q==d)
     73                                 wu = 1;
     74                 }
     75                 else if(a==b&&a==s&&a==t)
     76                 {
     77                     if(q==r&&q==i&&q==j)
     78                         if(k==l&&k==w&&k==x)
     79                             if(u==v&&u==c&&u==d)
     80                                 wu = 1;
     81                 }
     82             }
     83             else if(xu[4] && xu[5])
     84             {
     85                 if(a==c&&a==n&&a==p)
     86                 {
     87                     if(m==o&&m==j&&m==l)
     88                         if(i==k&&i==f&&i==h)
     89                             if(e==g&&e==b&&e==d)
     90                                 wu = 1;
     91                 }
     92                 else if(a==c&&a==f&&a==h)
     93                 {
     94                     if(e==g&&e==j&&e==l)
     95                         if(i==k&&i==n&&i==p)
     96                             if(m==o&&m==b&&m==d)
     97                                 wu = 1;
     98                 }
     99             }
    100             if(wu) puts("YES");
    101             else puts("NO");
    102         }
    103         else puts("NO");
    104     }
    105     return 0;
    106 }
    View Code
  • 相关阅读:
    MVC模式-----struts2框架(2)
    MVC模式-----struts2框架
    html的<h>标签
    jsp脚本元素
    LeetCode "Paint House"
    LeetCode "Longest Substring with At Most Two Distinct Characters"
    LeetCode "Graph Valid Tree"
    LeetCode "Shortest Word Distance"
    LeetCode "Verify Preorder Sequence in Binary Search Tree"
    LeetCode "Binary Tree Upside Down"
  • 原文地址:https://www.cnblogs.com/Taskr212/p/9740115.html
Copyright © 2011-2022 走看看