CF1906B Button Pressing 题解
前言
很水的
解法
将灯的
又根据冒泡排序的经典结论,即在进行上述操作的情况下,能将一个上面那样的异或前缀和序列任意重排——也就是说如果
现在在考虑操作
最终结论容易得到。
放代码(全场 Shortest):
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int t; cin>>t;
while(t--){
int n; string a,b; cin>>n>>a>>b;
auto f=[&](string s){
int c=0,p=0;
for(char i:s)c+=p^=i&1;
// 异或前缀和
return min(c,n-c+1);
// 实际上只需考虑两者中较小值
};
cout<<(f(a)==f(b)?"YES\n":"NO\n");
}
return 0;
}