#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
// vector<int> nums;
bool isYes(string x) {
for(int i = 1; i < x.size(); ++i) {
if(x[i] != x[i - 1]) continue;
else return false;
}
return true;
}
int main() {
int t;
cin >> t;
while(t--) {
string s, t;
int a;
cin >> a >> a;
cin >> s >> t;
if(s.size() == 1) cout << "Yes" << endl;
else {
if(isYes(s)) cout << "Yes" << endl;
else { // 此时s一定不是好的
if(t[0] != t[t.size() - 1] || isYes(t) == false) {
cout << "No" << endl;
}
else { // 此时t一定是好的,接下来通过判断首位,来判断是否可插入
char sign = '2';
bool stop = false; // 是否已经输出
for(int i = 1; i < s.size(); ++i) {
if(s[i] == s[i - 1] && sign == '2') {
sign = s[i];
}
else if(s[i] == sign) continue;
else if(s[i] == s[i - 1] && sign != '2') { // s中有0和1两种重复
stop = true;
}
}
if(stop == true) cout << "No" << endl; // s中有0和1两种重复
else if(sign != t[0]) cout << "Yes" << endl;
else if(sign == t[0]) cout << "No" << endl;
}
}
}
}
return 0;
}
<分支语句>【Codeforces Round 906 (Div. 2)】B. Qingshan Loves Strings
最新推荐文章于 2024-10-09 10:07:13 发布