题解 | 01序列

01序列

https://www.nowcoder.com/practice/b0c948dbe577485598b982a430d65c39

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k;
    cin>>k;
    int cnt=0;
    for(int i=0;i<n-2;i++){
        if((a[i]==0||a[i]==1)&&a[i+1]==0&&a[i+2]==0){
            a[i+2]=1;
            cnt++;
        }
    }
    if(cnt>=k)cout<<"true";
    else cout<<"false";
}

直接模拟就好了

全部评论
数据水了
点赞 回复 分享
发布于 02-04 15:53 安徽

相关推荐

01-12 20:31
东北大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务