Codeforces Round #444 (Div. 2) C.Solution for Cube 模拟

向题解低头,向大佬低头(。﹏。)orz……模拟也不能乱模啊……要好好分析题意,简化简化再简化orz敲黑板

六个面的魔方,能一步还原的情况一定是只有2个面是单色,其余四个面,每个面2种颜色,而且不会出现任意两面的两种颜色均相同的情况。

     如果每个面的颜色>2,肯定没有办法一步还原,这里每输入一个面用set计数,size=1的话记录一下单色面的面数f,size=2的话判断一下是否存在两个面的两种颜色均相同的情况,size>2当然就肯定不能一步还原啦,直接NO;

     如果单色面的面数>2,也是不能一步还原的……emmmm条件有些乱……感觉……就……一点一点凑……

#include<iostream>
#include<string.h>
#include<set>
using namespace std;
int c[7][7];
int a;
int main()
{
    int f = 0;
    for (int i = 0; i < 6; i++)
    {
        set<int>s;
        for (int j = 0; j < 4; j++)
        {
            cin >> a;
            s.insert(a);
        }
        if (s.size() == 1)
            f++;
        else if (s.size() == 2)
        {
            int n[2];
            int j = 0;
            for (auto it : s)   //emmm不太会用set……直接c[*s.begin()][*s.end()]的时候编译错误……有米有大佬给讲一讲哇
                n[j++] = it;
            c[n[0]][n[1]]++;
            if (c[n[0]][n[1]] > 1)
            {
                cout << "NO" << endl;
                return 0;
            }
        }
        else
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (f == 2)
        cout << "YES" << endl;
    else 
        cout << "NO" << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Egoist-/p/7795039.html