一个字符串中的 "01" 和 "10" 子串个数是否相同只取决于这个字符串开头和结尾的字符是否相同。
#include<bits/stdc++.h> #define int long long using namespace std; void solve() { int n;cin>>n; string s;cin>>s;s='#'+s; int l,r;cin>>l>>r; if(s[1]==s[r]) cout<<"Yes"<<endl; else { if(l==1||r==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T=1;cin>>T; while(T--) { solve(); } return 0; }