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⋅(a1⊕a2⊕?⊕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=2⋅6=2⋅(1⊕2⊕3⊕6)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=7≠2⋅1=2⋅(1⊕2⊕1⊕3)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 (1≤t≤100001≤t≤10000). The description of the test cases follows.

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

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤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 (0≤s≤30≤s≤3) — the number of elements you want to append.

In the second line, output ss integers b1,…,bsb1,…,bs (0≤bi≤10180≤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\n",cnt);
        for(int i=1;i<=cnt;i++)printf("%lld ",ans[i]);
        puts("");
    }
    return 0;
} 

原文地址:https://www.cnblogs.com/thmyl/p/12297422.html

时间: 2024-11-03 22:07:35

Codeforces 1270C 思维题的相关文章

CodeForces 1131B(思维题)

You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if the current score

CodeForces - 417B (思维题)

Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know th

CodeForces - 417A(思维题)

Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.

贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

题目传送门 1 /* 2 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 3 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0),先从1开始找到已经套好的娃娃层数, 4 其他是2次操作,还要减去k-1个娃娃是只要套上就可以 5 详细解释:http://blog.csdn.net/firstlucker/article/details/46671251 6 */ 7 #include <cstdio> 8 #i

codeforces 848B Rooter&#39;s Song 思维题

http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标轴,位置,延迟时间,发生碰撞则交换方向.求最后每个点的射出位置. 首先我们观察能得出两个结论,1. 类似蚂蚁爬树枝的问题,相遇只会交换方向,所以最后的射出点集只会因为碰撞而改变动点与射出点的对应关系,而不会增加减少射出点集.2.我们根据其射入位置和延迟时间可以计算出一个值v=pos-time,只有这

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)

Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is cal

Unique Encryption Keys (思维题 预处理)

题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; 如果离a最近的重复数字的位置 都大于b, 就说明没有重复数字. f[]数组需要预处理,从后向前. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector>

sdut 2847 Monitor (思维题)

题目 题意:给定a, b, x, y;  求使c, d; 使c:d = x :y; 且c<=a, d<=b, 而且c, d尽量大. 先求最小倍数, 再用最小倍数乘 x, y; 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 long long gcd(long long a, l

hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10

题目链接 题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性 分析: 类似cf的题目,比赛的时候都没想出来,简直笨到极点..... 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <vector> 7 #include &