焦糖布丁 题解(树上阶梯博弈+线性基)

题目链接

题目思路

原来是阶梯博弈的板子题。。然而我不会。。

只要奇数的数异或为0,则后手必胜,所以只要考虑是否有一些数异或为0即可

用线性基实现

代码

#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef long long ll;
const int maxn=60+5,inf=0x3f3f3f3f,mod=998244353;
const double eps=1e-6;
int n;
ll p[maxn],a[maxn];
inline ll ins(ll x) {
    for(int i = 60;i>=0; i--) {
        if (!(x &(1ll<<i)))  continue;
        // x的第i位是0
        if(!p[i]){
            p[i] = x;
            break;
        }
        x^= p[i];
    }
    return x;
}
signed main(){
    int _;scanf("%d",&_);
    while(_--){
        memset(p,0,sizeof(p));
        scanf("%d",&n);
        bool flag=0;
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
            ll x=ins(a[i]);
            if(x==0){
                flag=1;
            }
        }
        printf(flag?"Yes\n":"No\n");
    }

    return 0;
}


posted @ 2021-08-12 20:32  hunxuewangzi  阅读(50)  评论(0编辑  收藏  举报