Codeforces 1270C 思维题

Posted thmyl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 1270C 思维题相关的知识,希望对你有一定的参考价值。

C. Make Good
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let‘s call an array a1,a2,,ama1,a2,…,am of nonnegative integer numbers good if a1+a2+?+am=2(a1a2?am)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 

技术图片

 

 

#include<iostream>
#include<cstdio>
using namespace std;
int n;
long long ans[5];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        long long sum=0,a=0; 
        int cnt=0,x;
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            sum+=x;
            a^=x;
        }
        ans[++cnt]=(1LL<<50)+(sum%2);
        sum+=ans[cnt];
        a^=ans[cnt];
        ans[++cnt]=(2LL*a-sum)/2;
        ans[++cnt]=(2LL*a-sum)/2;
        printf("%d
",cnt);
        for(int i=1;i<=cnt;i++)printf("%lld ",ans[i]);
        puts("");
    }
    return 0;
} 

 

以上是关于Codeforces 1270C 思维题的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 1131B(思维题)

Codeforces Round #353 (Div. 2) A. Infinite Sequence 思维题

CodeForces 1005D Polycarp and Div 3(思维贪心dp)

CodeForces 1102C-简单的思维题

Codeforces 1137D - Cooperative Game - [交互题+思维题]

思维题,加强读题能力CodeForces - 705B