Good Bye 2019 C. Make Good

https://codeforces.com/contest/1270/problem/C

思路:利用异或的性质 a^a=0 先加一项把之前的异或和的影响消去 再加一项使得满足s=2x

s+x+y=2y y=s+x

官方:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        int n,x=0;
        ll s=0;
        cin>>n;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            s+=a;
            x^=a;
        }
    cout<<2<<endl;
    cout<<x<<' '<<s+x<<endl;    
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/wyh447154317/p/12164421.html