Topic links: https://vjudge.net/problem/CodeForces-1251B
Topic effect: to give you a number of 01 strings, you can swap any pair of characters, a string in the same, or in different strings
Because the subject is to limit freedom, as long as we judge all parity on the line. Comments should write in great detail
#include<set> #include<map> #include<list> #include<stack> #include<queue> #include<cmath> #include<cstdio> #include<cctype> #include<string> #include<vector> #include<climits> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define endl '\n' #define rtl rt<<1 #define rtr rt<<1|1 #define lson rt<<1, l, mid #define rson rt<<1|1, mid+1, r #define maxx(a, b) (a > b ? a : b) #define minn(a, b) (a < b ? a : b) #define zero(a) memset(a, 0, sizeof(a)) #define INF(a) memset(a, 0x3f, sizeof(a)) #define IOS ios::sync_with_stdio(false) #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<char, int> P2; const double pi = acos(-1.0); const double eps = 1e-7; const ll MOD = 1000000007LL; const int INF = 0x3f3f3f3f; const int _NAN = -0x3f3f3f3f; const double EULC = 0.5772156649015328; const int NIL = -1; template<typename T> void read(T &x){ x = 0;char ch = getchar();ll f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();} while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; } const int maxn = 1e3+10; int main(void) { int t; cin >> t; while(t--) { int n, n0 = 0, n1 = 0, odds = 0; string s; cin >> n; for (int i = 0; i<n; ++i) { CIN >> S; int size = s.size (); IF (size & 1 ) odds ++; // count the number of odd string for (CH Auto: S) { // count the number of 1's and 0 IF (CH == ' . 1 ' ) ++ N1; the else IF (CH == ' 0 ' ) ++ N0; } } IF (odds == . 1 && & N1 . 1 && & N0 . 1 ) COUT N1 << << endl; // if only an odd number of strings, then there is only one number is odd the else IF (& odds . 1 && ((N0 ~ & 1 && ~ N1 & 1 ) || (N0 & 1 && N1 & 1 ))) COUT N1 << << endl; // if the number is odd and odd-series is greater than 1, then only in one kind only odd number of characters when feasible the else IF (! odds && ((N1 & 1 ) || (n0 & 1 ))) cout << N1 <<endl; // if not odd string so two kinds of numbers can not appear odd the else IF (odds & ~ 1 && ((N1 & 1 && ~ N0 & 1 ) || (~ N1 & 1 && & N0 1 ))) COUT N1 << << endl; // if the number is an odd number strings is not greater than 1 and 0, as long as two kinds of numbers are even-number line the else COUT n-<< << endl; } return 0; }