luogu P3812 【模板】线性基

模板题。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

typedef long long LL;
LL a[100];
int n;

void Insert(LL x)
{
	for (int i=60;i>=0;i--)
		if(x&(1LL<<i))
			if(!a[i])
			{
				a[i]=x;
				break;
			}
			else
				x^=a[i];
}

LL Query_Max()
{
	LL now=0;
	for (int i=60;i>=0;i--)
		if(!(now&(1LL<<i)))
			now^=a[i];
	return now;
}

void init()
{
	scanf("%d",&n);
	LL x;
	for (int i=1;i<=n;i++)
		scanf("%lld",&x),Insert(x);
}

void work()
{
	printf("%lld
",Query_Max());
}

int main()
{
	init();
	work();
	return 0;
}
由于博主比较菜,所以有很多东西待学习,大部分文章会持续更新,另外如果有出错或者不周之处,欢迎大家在评论中指出!
原文地址:https://www.cnblogs.com/With-penguin/p/12839121.html