题解 | #小红的01串#
小红的01串
https://www.nowcoder.com/practice/09ca882b363a480aa33ab15e8cd2b039
每次操作只有三种可能
将两个1变成两个0
将两个1变成两个0
将一个1一个0变成一个0一个1
我们发现1和0的数量转换只能是2的倍数,所以如果1和0的数量都是奇数那就一定不可能,反之一定有解
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n;
string s;
void solve() {
cin >> s;
int n0 = count(s.begin(), s.end(), '0') % 2;
int n1 = count(s.begin(), s.end(), '1') % 2;
if (n0 && n1) {
cout << "No\n";
} else {
cout << "Yes\n";
}
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
cin >> __t;
while (__t--)
solve();
return 0;
}
