bzoj 2460: 元素 线性基

题目大意:

http://www.lydsy.com/JudgeOnline/problem.php?id=2460

题解:

RT
线性基裸题

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline void read(int &x){
	x=0;char ch;bool flag = false;
	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline void read(ull &x){
	x=0;char ch;bool flag = false;
	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int maxn = 1024;
struct Node{
	ull num,val;
	bool friend operator < (const Node &a,const Node &b){
		return a.val > b.val;
	}
}a[maxn];
ull p[80];
inline bool check(ull x){
	for(int i = 63;i>=0;--i){
		if((x>>i)&1){
			if(p[i] == 0){
				p[i] = x;
				return true;
			}else{
				x ^= p[i];
				if(x == 0) return false;
			}
		}
	}return false;
}
int main(){
	int n;read(n);
	for(int i=1;i<=n;++i){
		read(a[i].num);
		read(a[i].val);
	}
	sort(a+1,a+n+1);
	int ans = 0;
	for(int i=1;i<=n;++i){
		if(check(a[i].num)) ans += a[i].val;
	}printf("%d\n",ans);
	getchar();getchar();
	return 0;
}
posted @ 2017-02-28 21:17  Sky_miner  阅读(182)  评论(0编辑  收藏  举报