zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    	getchar();getchar();
    	return 0;
    }
    
  • 相关阅读:
    angular.js 渲染
    HTML5 与 CSS3 jQuery部分知识总结
    下拉滚动协议文本框展示样式(不可删除文本内容)
    06对象
    05数组
    1文字与字体
    04函数
    03循环
    02运算符
    01基础
  • 原文地址:https://www.cnblogs.com/Skyminer/p/6480971.html
Copyright © 2011-2022 走看看