B. Binary Removals(思维+模拟)

https://codeforces.com/contest/1499/problem/B


思路:

能确定最终答案的是00000,11111,00000111三种状态,然后按照构造成这几种状态check。

第三种状态枚举中间点i,[1,i]=0,[i+1,n]=1;

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=200;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char s[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    cin>>(s+1);
    LL len=strlen(s+1);
    bool flag1=1;bool flag2=1;bool flag3=0;
    ///全0
    LL pos=-1;
    for(LL i=1;i<=len;i++){
        if(s[i]=='1'&&i-pos>=2){
            pos=i;
        }
        else if(s[i]=='1'&&i-pos<2){
            flag1=0;
            break;
        }
    }
    ///全1
    pos=-1;
    for(LL i=1;i<=len;i++){
        if(s[i]=='0'&&i-pos>=2){
            pos=i;
        }
        else if(s[i]=='0'&&i-pos<2){
            flag2=0;
            break;
        }
    }
    ///前0后1
    for(LL i=1;i<=len;i++){///[1,i]为0,[i+1,len]为1
        LL p=-1;
        bool ok=1;
        for(LL j=1;j<=i;j++){
            if(s[j]=='1'&&j-p>=2){
                p=j;
            }
            else if(s[j]=='1'&&j-p<2){
                ok=0;
                break;
            }
        }
        if(ok==0) continue;
        for(LL j=i+1;j<=len;j++){
            if(s[j]=='0'&&j-p>=2){
                p=j;
            }
            else if(s[j]=='0'&&j-p<2){
                ok=0;
                break;
            }
        }
        if(ok==1){
            flag3=1;
            break;
        }
    }

    if(flag1||flag2||flag3){
        cout<<"YES"<<"\n";
    }
    else cout<<"NO"<<"\n";
  }
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值