HDU 5983 (Analog Rubik's Cube Simulation)

Source: Internet
Author: User

Test instructions is said to be given a 2*2 Rubik's Cube of the situation, asked whether it can be rotated not more than once to make the cube restoration.

The idea is to first in the input when the statistics have completed the number of faces, to be able to rotate at most once so that the cube restoration, then the completed surface number can only be 2 or 6 sides, here can be pruned.

If you have completed 6 sides, you will be able to recover;

If you have completed 2 sides, you have to use a rotation to complete the other six sides, began to use the structure to save, the result in the judgment of their own chaos ... Finally, 24 variables were set directly, A,b,c......w,x,

Hand made a small cube, too embarrassing ... (but have to say that this method is very good, easy to understand, and not disorderly ^_^)

The code is as follows:

1#include <bits/stdc++.h>2 using namespacestd;3 inta,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;4 BOOLxu[8];5 intMain ()6 {7     inttimes,cnt;8     BOOLWu;9scanf"%d",&Times );Ten      while(times--) One     { ACNT =0; -Memset (Xu,0,sizeof(Xu)); -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); the         if(a==b&&b==c&&c==d) -         { -++CNT; -xu[0] =1; +         } -         if(e==f&&f==g&&g==h) +         { A++CNT; atxu[1] =1; -         } -         if(i==j&&j==k&&k==l) -         { -++CNT; -xu[2] =1; in         } -         if(m==n&&n==o&&o==p) to         { +++CNT; -xu[3] =1; the         } *         if(q==r&&r==s&&s==t) $         {Panax Notoginseng++CNT; -xu[4] =1; the         } +         if(u==v&&v==w&&w==x) A         { the++CNT; +xu[5] =1; -         } $         if(cnt==6) puts ("YES"); $         Else if(cnt==2) -         { -Wu =0; the             if(xu[0]&&xu[2]) -             {Wuyi                 if(m==n&&m==u&&m==W) the                 { -                     if(v==x&&v==e&&v==f) Wu                         if(g==h&&g==r&&g==t) -                             if(q==s&&q==o&&q==p) AboutWu =1; $                 } -                 Else if(m==n&&m==r&&m==t) -                 { -                     if(q==s&&q==e&&q==f) A                         if(g==h&&g==u&&g==W) +                             if(v==x&&v==o&&v==p) theWu =1; -                 } $             } the             Else if(xu[1] && xu[3]) the             { the                 if(a==b&&a==w&&a==x) the                 { -                     if(u==v&&u==i&&u==j) in                         if(k==l&&k==s&&k==t) the                             if(q==r&&q==c&&q==d) theWu =1; About                 } the                 Else if(a==b&&a==s&&a==t) the                 { the                     if(q==r&&q==i&&q==j) +                         if(k==l&&k==w&&k==x) -                             if(u==v&&u==c&&u==d) theWu =1;Bayi                 } the             } the             Else if(xu[4] && xu[5]) -             { -                 if(a==c&&a==n&&a==p) the                 { the                     if(m==o&&m==j&&m==l) the                         if(i==k&&i==f&&i==h) the                             if(e==g&&e==b&&e==d) -Wu =1; the                 } the                 Else if(a==c&&a==f&&a==h) the                 {94                     if(e==g&&e==j&&e==l) the                         if(i==k&&i==n&&i==p) the                             if(m==o&&m==b&&m==d) theWu =1;98                 } About             } -             if(WU) puts ("YES");101             ElsePuts"NO");102         }103         ElsePuts"NO");104     } the     return 0;106}
View Code

HDU 5983 (Analog Rubik's Cube Simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.