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.
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.
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
NO
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
YES
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.
思路:
六个面有三种情况,每次一定是有两个相邻的才行,所以我们这里分类讨论,代码如下:
AC code
#include<bits/stdc++.h>
using namespace std;
int arr[25] = {0};
bool f(int a, int b, int c, int d)
{
return ((arr[a] == arr[b]) && (arr[c] == arr[d]) && (arr[a] == arr[c]));
}
int main()
{
for(int i=1;i<25;i++) cin>>arr[i];
bool flag = 0;
if(f(1,2,3,4) && f(9,10,11,12))
{
if(f(5,6,15,16) && f(17,18,7,8) && f(21,22,19,20) && f(13,14,23,24)) flag = 1;
if(f(13,14,7,8) && f(5,6,19,20) && f(17,18,23,24) && f(21,22,15,16)) flag = 1;
}
if(f(13,14,15,16) && f(17,18,19,20))
{
if(f(1,3,6,8) && f(5,7,10,12) && f(9,11,21,23) && f(22,24,2,4)) flag = 1;
if(f(2,4,5,7) && f(6,8,9,11) && f(10,12,22,24) && f(21,23,1,3)) flag = 1;
}
if(f(5,6,7,8) && f(21,22,23,24))
{
if(f(15,13,3,4) && f(1,2,17,19) && f(18,20,10,9) && f(12,11,16,14)) flag = 1;
if(f(16,14,1,2) && f(3,4,18,20) && f(17,19,12,11) && f(15,13,10,9)) flag = 1;
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}
本文介绍了一种通过编程判断2x2x2魔方是否可以通过一次90度旋转某一面对应解决的方法。文章提供了一个详细的算法实现过程,包括对魔方状态的输入和对特定条件的检查。
456

被折叠的 条评论
为什么被折叠?



