链接:
https://codeforces.com/contest/1270/problem/C
题意:
Let's call an array a1,a2,…,am of nonnegative integer numbers good if a1+a2+⋯+am=2⋅(a1⊕a2⊕⋯⊕am), where ⊕ denotes the bitwise XOR operation.
For example, array [1,2,3,6] is good, as 1+2+3+6=12=2⋅6=2⋅(1⊕2⊕3⊕6). At the same time, array [1,2,1,3] isn't good, as 1+2+1+3=7≠2⋅1=2⋅(1⊕2⊕1⊕3).
You are given an array of length n: a1,a2,…,an. Append at most 3 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.
思路:
想多了发现是sb题,让右边为0,加个左边就行了
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
int n;
int a[MAXN];
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> n;
LL ans = 0, sum = 0;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
ans ^= a[i];
sum += a[i];
}
if (ans*2 == sum)
cout << 0 << endl << endl;
else if (ans == 0)
{
cout << 1 << endl;
cout << sum << endl;
}
else
{
sum += ans;
cout << 2 << endl;
cout << ans << ' ' << sum << endl;
}
}
return 0;
}