Link
Question
给出一个 01串,可以在任意一个位置 \(i\) 插入一个字符,如果 \(a_i \ne a_{i+1}\) 插入的字符为 \(0\) 否则插入的字符为 \(1\)
问,是否可以通过任意次操作使得串中 \(0\) 的数量比 \(1\) 多
Solution
如果一个串
- 都为 \(0\) 肯定符合
- 都为 \(1\) 不符合
- 有 \(0\) 有 \(1\) ,在交界处插入 \(0\) ,直到 \(0\) 的个数比 \(1\) 多
所以,只需要判断是否存在 \(0\)
Code
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch<='9'&&ch>='0')ret=ret*10+ch-'0',ch=getchar();
return ret*f;
}
void solve(){
int N=read();
string s;
cin>>s;
for(int i=0;i<s.length();i++)
if(s[i]=='0') {
printf("YES\n");return ;
}
printf("NO\n");
}
int main(){
int T=read();
while(T--) solve();
}