应用
https://blog.csdn.net/weixin_30386713/article/details/101100418
例题:
自己的模板代码(功能还需完善):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 60;
ll a[maxn + 10];
void insert(ll x){//依次插入n个数到a数组
for(int i=maxn;i>=0;i--){
if(x&(1<<i)){
if(!a[i]){
a[i] = x;
break ;
}
x ^= a[i];
}
}
}
bool check(ll x)//x是否能被给出的n个数通过异或得到
{
for(int i=maxn;i>=0;i--){
if(x&(1<<i)){
if(!a[i])
return false;
x ^= a[i];
}
}
if(x == 0)
return true ;
return false ;
}
ll querymax(){//n个值的异或最大值
ll ans = 0;
for(int i=maxn;i>=0;i--){
if((ans^a[i]) > ans)
ans ^= a[i];
}
return ans;
}
ll querymin(){//n个值的异或最小值
for(int i=0;i<=maxn;i++)
if(a[i])
return a[i];
return 0;
}
int main()
{
int n,t;
ll x;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&x),insert(x);
cin>>t;
while(t--){
scanf("%lld",&x);
if(check(x))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
京公网安备 11010502036488号