AC

名字不要取太长像我这样应该刚刚好  •  14天前


include <bits/stdc++.h>

using namespace std;

int main() {

int q, n;
string s1, s2, t1, t2;
int x1, x2, y1, y2, cnt = 0;
cin >> q;
while (q--) {
	cin >> n >> s1 >> s2 >> t1 >> t2;
	x1 = x2 = y1 = y2 = cnt = 0;
	for (int i = 0, j = 0; i < n || j < n;) {
		if (x1 + y1 == 0) {
			if (t1[i] == '0') {
				if (s1[i] == '0') 
					x1++;
				 else {
					y1++;
					i++;
				}
			} else {
				while (t1[i] == '1') {
					if (s1[i] == '0') 
						x1++;
					 else 
						y1++;						
					i++;
				}
			}
		}
		if (x2 + y2 == 0) {
			if (t1[j] == '0') {
				if (s2[j] == '0') 
					x2++;
				 else {
					y1++;
					j++;
				}
			} else {
				while (t2[j] == '1') {
					if (s2[j] == '0') 
						x2++;
					 else 
						y2++;						
					j++;
				}
			}
		}
		int o = min(y1, y2);
		int z = min(x1, x2);
		cnt += o + z;
		y1 -= o;
		y2 -= o;
		x1 -= z;
		x2 -= z;
		int e = min(y1, x2);
		y1 -= e;
		x2 -= e;
		e = min(y2, x1);
		y2 -= e;
		x1 -= e;
	}
	cout<<cnt<<endl;
}
return 0;

}


评论:

请先登录,才能进行评论