等价串
题解:01 等价于 10,因为变换都是对称的,所以将a,b串划成最简形式,比较就行了。
#include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define lson root << 1 #define INF (int)2e9 + 7 #define maxn (int)1e4 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; int T, n, m; char a[105], b[105]; int main() { cin >> T; while(T--){ cin >> n >> m; scanf("%s", a); scanf("%s", b); int a0 = 0, a1 = 0; for(int i = 0; i < n; i++) { if(a[i] == '0') a0++; else a1++; } int b0 = 0, b1 = 0; for(int i = 0; i < m; i++) { if(b[i] == '0') b0++; else b1++; } a0 %= 3; a1 %= 3; b0 %= 3; b1 %= 3; a0 = (a0 + a1 * 2) % 3; b0 = (b0 + b1 * 2) % 3; if(a0 == b0) puts("YES"); else puts("NO"); } return 0; }