本文主要是介绍每日错题(2024年9月1日),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Problem - C - Codeforces
思路非常简单,但是对我感觉比较难想
sum总和
sum_异或和
sum + sum_ + x = 2 * x
解得,x = sum + sum_
#include <bits/stdc++.h>using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc u << 1
#define rc u << 1 | 1void solve();const int N = 1e6 + 10;signed main() {IOS;ll t = 1;cin >> t;while (t--)solve();return 0;
}
//sum+ === ___(suoyoujin)
void solve() {ll n; cin >> n;vector<ll> a(n+1);ll sum = 0,sum_ = 0;for(int i = 1; i <= n; ++ i){cin >> a[i];sum_ = sum_ ^ a[i];sum += a[i];}if((sum_<<1) == sum){cout << 0 << endl;cout << endl;return;}cout << 2 << endl;cout << sum_ << " " << sum_ + sum << endl;
}
这篇关于每日错题(2024年9月1日)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!