To xor or not to xor SGU - 275 线性基入门题

 

线性基是一个序列的异或和基底。

1.原序列里面的任意一个数都可以由线性基里面的一些数异或得到

2.线性基里面的任意一些数异或起来都不能得到0

3.线性基里面的数的个数唯一,并且在保持性质一的前提下,数的个数是最少的

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,-1,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/

ll d[M];
void in(ll x)
{
	for(int i=60;i>=0;i--)
	{
		if(x>>i&1)
		{
			if(d[i])x^=d[i];
			else
			{
				d[i]=x;
				break;
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n,x;
  	cin>>n;
  	for(int i=1;i<=n;i++)cin>>x,in(x);
  	ll ans=0;
  	for(int i=60;i>=0;i--)
  	{
  	//	if(d[i])cout<<i<<" "<<d[i]<<" "<<ans<<endl;
  		if((ans^d[i])>ans)ans^=d[i];
	}
	cout<<ans<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值