Codeforces 887C

来源:互联网 发布:高智商犯罪 知乎 编辑:程序博客网 时间:2024/06/05 06:24


C. Solution for Cube


time limit per test 2 seconds

memory limit per test     256 megabytes


During the breaks between competitions, top-model Izabella triesto develop herself and not to be bored. For example, now she tries to solveRubik's cube 2x2x2.

It's too hard to learn to solve Rubik's cube instantly, so shelearns to understand if it's possible to solve the cube in some state using90-degrees rotation of one face of the cube in any direction.

To check her answers she wants to use a program which will forsome 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 integersai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4occurrences 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.


【题意】


感觉题目描述不是很清楚,猜测一下题意:给出六个面,每个面的四个方块的颜色,然后你可以随机拼凑,问能否在转动且转动一次的情况下将魔方还原。


【思路】


首先,必须转一次。所以六个面的情况应该是这样:其中两个面的颜色相同,其余四个面每个面两种颜色,且这四个面如果各从一种颜色向另一种颜色连边的话,只能形成一个环,这样才能满足一次能还原。


举个例子:


假设四个面的颜色分别是1,2;2,4;4,3;3,1。


那么可以构成如下排列一次还原

1 2

2 4

4 3

3 1

但如果出现了1,2;2,1这种情况显然就不满足了。


#include <cstdio>#include <cmath>#include <set>#include <cstring>#include <algorithm>using namespace std;#define mst(a,b) memset((a),(b),sizeof(a))#define rush() int T;scanf("%d",&T);while(T--)typedef long long ll;const int maxn = 15;const ll mod = 10;const int INF = 0x3f3f3f3f;const double eps = 1e-9;int a[maxn];int mp[maxn][maxn];int main(){    int ans=0;    for(int i=0; i<6; i++)    {        set<int>s;        for(int j=0; j<4; j++)        {            int x;            scanf("%d",&x);            s.insert(x);        }        if(s.size()==1) ans++;              //单个面颜色相同        else if(s.size()==2)                //单个面两种颜色,需要记录        {            int pre=-1,pre1=-1;            for(auto it: s)            {                if(pre==-1) pre=it;                else pre1=it;            }            if(pre>pre1) swap(pre,pre1);            mp[pre][pre1]++;                //标记        }        else                                //单个面出现三种及以上颜色,显然不满足        {            puts("NO");            return 0;        }    }    if(ans==2)                              //两个面相同,四个面各两种颜色才满足条件    {        for(int i=1; i<=6; i++)            for(int j=1; j<=6; j++)            {                if(mp[i][j]>=2)                {                    puts("NO");                    return 0;                }            }        puts("YES");    }    else puts("NO");}








原创粉丝点击