题解:CF2171C1 Renako Amaori and XOR Game (easy version)

· · 题解

思路:

考虑贪心,既然只有 01,那么有两种情况:1 的总数为偶数个,异或后和为 0,若有奇数个 1 那么异或和为 1。尽量让最终答案为 1。那么只需要判断:轮到我操作时,若我手上的 1 的个数为偶数个,就看看能不能通过交换使个数增加 1 或减少 1,使我的和为 1

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 2e5 + 10;
int t,n,a[N],b[N];
void solve(){
    cin >> n;
    int cnt1 = 0,cnt2 = 0;
    bool f1 = 0,f2 = 0;
    for(int i = 1;i <= n;i ++){cin >> a[i];cnt1 += a[i];}
    for(int i = 1;i <= n;i ++){cin >> b[i];cnt2 += b[i];}
    for(int i = 1;i <= n;i ++){
        if(a[i] == b[i])continue;
        if(i % 2){
            if(cnt1 % 2 == 0){
                if(a[i] == 1 and b[i] == 0){
                    cnt1 --;
                    cnt2 ++;
                }
                if(a[i] == 0 and b[i] == 1){
                    cnt1 ++;
                    cnt2 --;
                }
            }
        }else{
            if(cnt2 % 2 == 0){
                if(a[i] == 0 and b[i] == 1){
                    cnt1 --;
                    cnt2 ++;
                }
                if(a[i] == 1 and b[i] == 0){
                    cnt2 ++;
                    cnt1 --;
                }
            }
        }
    }
    if((cnt1 % 2 == 0 and cnt2 % 2 == 0) or (cnt1 % 2 and cnt2 % 2))puts("Tie");
    else if(cnt1 % 2 == 0)puts("Mai");
    else if(cnt2 % 2 == 0)puts("Ajisai");
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> t;
    while(t --){
        solve();
    }
    return 0;
}