• 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;
    }
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    落忆枫音(我们终将成为”枫音乡的过客“)
    PID221 / 烦人的幻灯片☆ x
    codevs 5971 打击犯罪 x
    洛谷 P2330 [SCOI2005] 繁忙的都市 x
  • 原文地址:https://www.cnblogs.com/lusiqi/p/11715343.html
Copyright © 2020-2023  润新知