• BZOJ_3687_简单题_bitset


    BZOJ_3687_简单题_bitset

    Description

    小呆开始研究集合论了,他提出了关于一个数集四个问题:
    1.子集的异或和的算术和。
    2.子集的异或和的异或和。
    3.子集的算术和的算术和。
    4.子集的算术和的异或和。
        目前为止,小呆已经解决了前三个问题,还剩下最后一个问题还没有解决,他决定把
    这个问题交给你,未来的集训队队员来实现。

    Input

    第一行,一个整数n。
    第二行,n个正整数,表示01,a2….,。

    Output

     一行,包含一个整数,表示所有子集和的异或和。

    Sample Input

    2
    1 3

    Sample Output

    6


    统计每个和的权值出现的次数,如果出现奇数次就加到贡献里。

    因为总和不超过2000000.

    可以用bitset优化,对于每个x,异或上f<<x。

    代码:

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <bitset>
    using namespace std;
    bitset<2000050>f;
    int main() {
        int n,k,x,i,sum=0,ans=0;
        f[0]=1;
        scanf("%d",&n);
        for(i=1;i<=n;i++) {
            scanf("%d",&x);
            f^=(f<<x);
            sum+=x;
        }
        for(i=1;i<=sum;i++) {
            if(f[i]) ans^=i;
        }
        printf("%d
    ",ans);
    }
    
  • 相关阅读:
    使用phpize安装php模块
    centos如何卸载软件
    修改centos环境变量
    linux系统安装php扩展
    php单入口session处理
    session阻塞机制,解决方法
    uploadify插件的使用
    php图片上传代码
    validate插件的使用
    datepicker使用
  • 原文地址:https://www.cnblogs.com/suika/p/8967217.html
Copyright © 2020-2023  润新知