P10370「LAOI-4」Mex Tower (Hard ver.)

/*
	和上题一样只不过,是换成了检验答案,还是找规律,
	自己看看吧awa
    O(n)
    实际上有点卡数据的意思,但是能过,思想也行,除非极限数据不然卡不掉,卡掉了就在卡掉极限数据
*/

#include <iostream>
#include <algorithm>
#include <cstring>
#include <ctime>

using namespace std;

int n, m;
string s;

char get(char a, char b)
{
    int sum = 0;
    if (a == '0' || b == '0') sum ++ ;
    if (sum == 1 && (a == '1' || b == '1')) sum ++ ;
    return sum + '0';
}

string make(string s1)
{
    string s2;
    int len = s1.size() - 1;
    // cout << len << endl;
    for (int i = 0; i < len; i ++ )
    {
        s2 += get(s1[i], s1[i + 1]);
    }
    return s2;
}

int main()
{
    int T;
    cin >> T;
    while (T -- )
    {
        cin >> n;
        
        s.clear();
        for (int i = 0; i < n; i ++ ) 
        {
            int c;
            scanf("%d", &c);
            if (c > 2) c = 2;
            s += (char)(c + '0');
        }
        if (n == 1) 
        {
            cout << "No" << endl;
            continue;
        }
        int cnt = 10;
        while (n > 1 && cnt -- ) s = make(s), n -- ; // 用于搞定特殊情况如2222222
        
        if (n & 1)
        {
        	n /= 2;
        	s = s.substr(n, 1);
        }
        else 
        {
        	n /= 2;
        	n -- ;
        	s = s.substr(n, 2);
        	s = make(s);
        }
        
        if (s.size() == 1 && s.compare("2") == 0) cout << "Yes";
        else cout << "No";
        puts("");
    }
    cout << clock();
}
// O(n^2)虽然是O(n^2)但是保对
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int n, m;
string s;

char get(char a, char b)
{
    int sum = 0;
    if (a == '0' || b == '0') sum ++ ;
    if (sum == 1 && (a == '1' || b == '1')) sum ++ ;
    return sum + '0';
}

string make(string s1)
{
    string s2;
    int len = s1.size() - 1;
    for (int i = 0; i < len; i ++ )
    {
        s2 += get(s1[i], s1[i + 1]);
    }
    return s2;
}

int main()
{
    int T;
    cin >> T;
    while (T -- )
    {
        cin >> n;
        s.clear();
        for (int i = 0; i < n; i ++ ) 
        {
            char c;
            cin >> c;
            s += c;
            // cout << c;
        }
        // cout << s << endl;
        while ( -- n) s = make(s);
        if (s[0] == '2') cout << "Yes";
        else cout << "No";
        puts("");
    }
}
posted @ 2024-04-20 19:59  blind5883  阅读(20)  评论(0编辑  收藏  举报