#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int t; cin >> t;
while (t--) { int n; cin >> n; int cnt = 0; bool flag = 0; for (int i = 0; i < n; i++) { int x; cin >> x; cnt += x % 2; flag |= x % 2 == 0; } if (flag) cnt++; else cnt--; cout << cnt << endl; }
#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end(), greater<>()); int id = -1; for (int i = 1; i < n; i++) { if (a[i] == a[i - 1]) { id = i; break; } }
if (id == -1) { cout << -1 << endl; } else { vector<int> res; res.push_back(a[id]); res.push_back(a[id]);
int lst = -1, now = -1; int minn = 1e9, id1 = -1, id2 = -1; for (int i = 0; i < n; i++) { if (i == id || i == id - 1) { continue; } lst = now; now = i; if (lst == -1) continue; if (a[lst] - a[now] < minn) { minn = a[lst] - a[now]; id1 = lst; id2 = now; } }
#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
intmain(){ int t; cin >> t;
while (t--) { int n, m; cin >> n >> m; multiset<int> a, b; for (int i = 0; i < n; i++) { int x; cin >> x; a.insert(x); } for (int i = 0; i < m; i++) { int x; cin >> x; b.insert(-x); }
while (!b.empty() && b.size() <= a.size()) { auto x = -(*b.begin()); b.erase(b.begin()); if (a.find(x) != a.end()) { a.extract(x); } else { int y = x / 2, z = x - y; b.insert(-y); b.insert(-z); } }
cout << (a == b ? "Yes" : "No") << endl; // 其实是a,b皆空 }
#include<bits/stdc++.h> using ll = longlong; usingnamespace std;
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int t; cin >> t;
while (t--) { string s, t; cin >> s >> t;
deque<int> S, T;
// 将 s 转换为 S 数组,记录连续 0/1 的长度 int len = 0; for (int i = 1; i < s.size(); i++) { len++; if (s[i] != s[i - 1]) { S.push_back(len); len = 0; } } len++; S.push_back(len); S.push_back(0); S.push_back(0); S.push_back(0); S.push_back(0);
// 将 t 转换为 T 数组,记录连续 0/1 的长度 len = 0; for (int i = 1; i < t.size(); i++) { len++; if (t[i] != t[i - 1]) { T.push_back(len); len = 0; } } len++; T.push_back(len);
int res = 0; bool ok = 1;
// 如果 t 的第一个字符与 s 的第一个字符不同,那么 s 必须先交换一次 if (t[0] != s[0]) { S[2] += S[0]; S.pop_front(); res++; }
while (!T.empty()) { int x = S.front(); S.pop_front(); int y = T.front(); T.pop_front();
while (x < y && S.size() >= 3) { // 交换 S[0] 和 S[1] x += S[1]; S[2] += S[0]; S.pop_front(); S.pop_front(); res++; } if (x != y || S.empty()) { ok = 0; break; } }
if (!ok) { cout << -1 << endl; } else { cout << res << endl; } }