zoukankan      html  css  js  c++  java
  • [BJWC2011]元素

    [BJWC2011]元素

    题目大意:

    (n(nle1000))个物品,每个物品有两个属性:序号(a_i(a_ile10^{18}))和权值(b_i(b_ile10000))。现在从中选取若干个物品,使得序号异或和不为(0),求权值和最大值。

    思路:

    按照权值从大到小排序贪心地构造线性基。

    源代码:

    #include<cstdio>
    #include<cctype>
    #include<algorithm>
    #include<functional>
    typedef long long int64;
    inline int64 getint() {
    	register char ch;
    	while(!isdigit(ch=getchar()));
    	register int64 x=ch^'0';
    	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
    	return x;
    }
    const int N=1000,B=60;
    struct Node {
    	int64 id;
    	int w;
    	bool operator > (const Node &rhs) const {
    		return w>rhs.w;
    	}
    };
    Node a[N],b[B];
    int main() {
    	const int n=getint();
    	for(register int i=0;i<n;i++) {
    		a[i].id=getint();
    		a[i].w=getint();
    	}
    	std::sort(&a[0],&a[n],std::greater<Node>());
    	for(register int i=0;i<n;i++) {
    		for(register int j=B-1;j>=0;j--) {
    			if((a[i].id>>j)&1) {
    				if(b[j].id==0) {
    					b[j]=a[i];
    					break;
    				}
    				a[i].id^=b[j].id;
    			}
    		}
    	}
    	int ans=0;
    	for(register int i=0;i<B;i++) {
    		ans+=b[i].w;
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    jquery02
    jquery01
    oracle04_plsql
    oracle03
    oracle02
    oracle01
    selenium
    爬取京东商品信息并保存到MongoDB
    python pymongo操作之增删改查
    MongoDB 数据库表删除
  • 原文地址:https://www.cnblogs.com/skylee03/p/9745663.html
Copyright © 2011-2022 走看看