zoukankan      html  css  js  c++  java
  • Good Bye 2019 C. Make Good (异或的使用)

    Let's call an array a1,a2,,ama1,a2,…,am of nonnegative integer numbers good if a1+a2++am=2(a1a2am)a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am), where ⊕denotes the bitwise XOR operation.

    For example, array [1,2,3,6][1,2,3,6] is good, as 1+2+3+6=12=26=2(1236)1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6). At the same time, array [1,2,1,3][1,2,1,3] isn't good, as 1+2+1+3=721=2(1213)1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3).

    You are given an array of length nn: a1,a2,,ana1,a2,…,an. Append at most 33 elements to it to make it good. Appended elements don't have to be different. It can be shown that the solution always exists under the given constraints. If there are different solutions, you are allowed to output any of them. Note that you don't have to minimize the number of added elements!. So, if an array is good already you are allowed to not append elements.

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1t100001≤t≤10000). The description of the test cases follows.

    The first line of each test case contains a single integer n(1n105)(1≤n≤105) — the size of the array.

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤ai≤109) — the elements of the array.

    It is guaranteed that the sum of nn over all test cases does not exceed 105105.

    Output

    For each test case, output two lines.

    In the first line, output a single integer ss (0s30≤s≤3) — the number of elements you want to append.

    In the second line, output ss integers b1,,bsb1,…,bs (0bi10180≤bi≤1018) — the elements you want to append to the array.

    If there are different solutions, you are allowed to output any of them.

    Example
    input
    Copy
    3
    4
    1 2 3 6
    1
    8
    2
    1 1
    
    output
    Copy
    0
    
    2
    4 4
    3
    2 6 2
    
    Note

    In the first test case of the example, the sum of all numbers is 1212, and their ⊕ is 66, so the condition is already satisfied.

    In the second test case of the example, after adding 4,44,4, the array becomes [8,4,4][8,4,4]. The sum of numbers in it is 1616, ⊕ of numbers in it is 88.

     

     

    #include <iostream>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <set>
    //#include <unordered_map>
    #include <map>
    #include <queue>
    #include <cstdio>
    #include <cstdlib>
    #include <string>
    #include <utility>
    #include <cstring>
    //#include <multimap>
    #define ll long long
    #define inf 0x3f3f3f3
    using namespace std;
    const int mxn = 2e5+10;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ls now<<1,l,mid
    #define rs now<<1|1,mid+1,r
    #define lc now<<1
    #define rc now<<1|1
    #define upsum(now) rt[now].sum =rt[now<<1].sum + rt[now<<1|1].sum ;
    #define upmx(now) rt[now].mx = max(rt[now<<1].mx , rt[now<<1|1].mx) ;
    #define pb push_back
    ll n,m,k,t,mx,mn,l,r,dp[mxn],u,v,cost,ans[mxn],a[mxn];
    int l1[mxn>>1],l2[mxn>>1], r1[mxn>>1],r2[mxn>>1];
    string str,ch;
    int main()
    {
        TLE;
        cin>>t;
        while(t--)
        {
            cin>>n;
            ll l,r;
            for(int i=1;i<=n;i++)
            {
                cin>>dp[i];
                if(i==1)
                    l = dp[i] , r = dp[i] ;
                else
                    l+=dp[i] , r^=dp[i] ;
            }
            if(l==r*2)
                cout<<0<<endl<<endl;
            else
                cout<<2<<endl<<r<<" "<<l+r<<endl;
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    隧道适配器,本地连接过多的解决办法
    C# 遍历HashTable
    sql2005 数据库转为sql 2000数据库的步骤
    自动扫描IP代理地址和自动切换IP的软件
    JS实现网页图片延迟加载[随滚动条渐显]
    批量修改hosts
    C#.NET获取当前月份最大天数
    如何让js调用不影响页面的加载速度?
    在sql中如何替换去掉回车符?
    Linq(01)对Linq的疑问及学习路径
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12122009.html
Copyright © 2011-2022 走看看