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

    传送门

    线性基有一个重要的性质:线性基中任意一个非空子集的异或和不为0。

    这好像就是给这道题准备的!

    立即得到做法:按权值从大到小排序,直接插入线性基计算答案即可。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<cstring>
    #define rep(i,a,n) for(register int i = a;i <= n;i++)
    #define per(i,n,a) for(register int i = n;i >= a;i--)
    #define enter putchar('
    ')
    #define pr pair<int,int>
    #define mp make_pair
    #define fi first
    #define sc second
    using namespace std;
    typedef long long ll;
    const int M = 100005;
    const int N = 10000005;
     
    ll read()
    {
       ll ans = 0,op = 1;char ch = getchar();
       while(ch < '0' || ch > '9') {if(ch == '-') op = -1;ch = getchar();}
       while(ch >='0' && ch <= '9') ans = ans * 10 + ch - '0',ch = getchar();
       return ans * op;
    }
    
    struct stone
    {
       ll num,mag;
       bool operator < (const stone &g) const
       {
          return mag > g.mag;
       }
    }s[M];
    
    ll n,ans,p[100];
    
    void insert(ll x,ll v)
    {
       per(i,63,0)
       {
          if(!(x >> i)) continue;
          if(!p[i]) {p[i] = x,ans += v;break;}
          x ^= p[i];
       }
    }
    
    int main()
    {
       n = read();
       rep(i,1,n) s[i].num = read(),s[i].mag = read();
       sort(s+1,s+1+n);
       rep(i,1,n) insert(s[i].num,s[i].mag);
       printf("%lld
    ",ans);
       return 0;
    }
    
    
  • 相关阅读:
    Uva 11806 拉拉队 二进制+容斥原理 经典!
    CSU CHESS
    hdu 4049 Tourism Planning 状态压缩dp
    HDOJ 4661: Message Passing(找递推公式+逆元)
    HDU
    hdu4647(思路啊!)
    spoj 370. Ones and zeros(搜索+同余剪枝+链表存数(可能越界LL))
    URAL
    URAL
    hdu4614 (二分线段树)
  • 原文地址:https://www.cnblogs.com/captain1/p/10206587.html
Copyright © 2011-2022 走看看