zoukankan      html  css  js  c++  java
  • bitmat


    Time Limit: 10 Sec  Memory Limit: 512 MB
    Submit: 1138  Solved: 556
    [Submit][Status][Discuss]

    Description

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

    Input

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

    Output

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

    Sample Input

    2
    1 3

    Sample Output

    6

    HINT

    【样例解释】

      6=1 异或 3 异或 (1+3)

    【数据规模与约定】

    ai >0,1<n<1000,∑ai≤2000000。

    另外,不保证集合中的数满足互异性,即有可能出现Ai= Aj且i不等于J

    思路:

    就举个例子来简单说明一下吧!

    输入 3

      1  2  3

                                        01

              10

             =  11

             1100          

              =1111

                1111000

           =1110111

        1  1  1  0  1  1  1

    下标  6  5  4  3  2  1  0

    等价    1+2+3 2+3  1+3    1+2 2  1  0

                3

    一个数异或0没有什么影响

    因为下标为3有两个式子,于是异或后为0

    代码:

    #include<cstdio>
    #include<iostream>
    #include<bitset>
    #include<cstring>
    using namespace std;
    int N;
    bitset<2000001>bit;
    int main()
    {
        scanf("%d",&N);
        bit[0]=1;
        while(N--)
        {
            int x;
            scanf("%d",&x);
            bit^=bit<<x;//bit = bit^(bit<<x)
        }
        int ans=0;
        for(int i=2000000;i>=0;i--)
            if(bit[i]==1) 
                ans^=i;
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    bootstrap table本地数据使用方法
    openlayers+geoserver ImageWMS过滤动态刷新图层
    openlayers+geoserver+wms实现空间查询,属性查询
    openlayers4.6.5官方api、实例、开发包
    js判断点在线上位置,距离各端点距离算法
    openlayers之style符号化
    js判断向量叉点 并求出交点坐标
    利用jquery判断点是否在椭圆内
    JavaScript高级程序设计21.pdf
    JavaScript高级程序设计20.pdf
  • 原文地址:https://www.cnblogs.com/lusiqi/p/11715343.html
Copyright © 2011-2022 走看看