1 条题解

  • 0
    @ 2026-10-18 19:35:11

    简单思路 一句话核心 操作 001↔100 和 110↔011,本质就是交换相差 2 的两个字符。

    由此推出 一个字符每次只能移动 2 格,所以奇数位置上的字符永远在奇数位置,偶数位置上的永远在偶数位置;

    #include<bits/stdc++.h>
    using namespace std;
    #define endl '\n'
    void solve() {
    	int n;
    	cin >> n;
    	string s1, s2;
    	cin >> s1 >> s2;
    	int a = 0, b = 0, c = 0, d = 0;
    	for (int i = 0; i < n; i++) {
    		if (s1[i] == '1') {
    			if (i % 2 == 0) {
    				a++;
    			} else {
    				b++;
    			}
    		}
    		if (s2[i] == '1') {
    			if (i % 2 == 0) {
    				c++;
    			} else {
    				d++;
    			}
    		}
    	}
    	if (a == c && b == d) {
    		cout << "YES" << endl;
    	} else {
    		cout << "NO" << endl;
    	}
    }
    signed main() {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	cout.tie(0);
    	int t = 1;
    	cin >> t;
    	while (t--) {
    		solve();
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    1246
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    16
    已通过
    5
    上传者