题意就是 在这个数串中插入1构成一个最长的连续1的区间串

如何做?我们可以对长度进行二分

从1到n二分长度 然后在对这个长度拿到数串中查看是否能构成最终我们想要的最长匹配串

这里我们可以利用一个前缀和数组 统计从1到i的0的个数 由于必然是递增数组 就满足了二分

的“有序”条件 。

#include<bits/stdc++.h>
using namespace std;
int a[300010],s[300010];
int n,k,L;
bool che(int x)
{for(int i=1;i<=n;i++){int r = i+x-1;if(r>n)return 0;if(s[r]-s[i-1]<=k){//如果s[r]-s[i-1]<=k说明这两个下标下之间0的个数<=k也就说满足条件 就会返回1 并记录区间左端点L = i;return 1;}}return 0;
}
int main()
{cin>>n>>k;s[0]=0; for(int i=1;i<=n;i++){ cin>>a[i];s[i]=s[i-1]+(a[i]==0);}int M=0,u=0;int l = 1,r=n;while(l<=r){int mid = (l+r)>>1;if(che(mid)){// 如果这里返回1 说明区间满足条件 就会记录长度 尝试更长的长度 u = mid;l = mid+1;}else r = mid-1;// 不满足条件 说明数串长度过长 需要截短}for(int i=L;i<=L+u-1;i++)a[i]=1;cout<<u<<endl;for(int i=1;i<=n;i++){cout<<a[i];if(i==n)puts("");else cout<<" ";}return 0;}

CodeForces - 660C Hard Process相关推荐

  1. CodeForces 660C Hard Process

    预处理前缀和+枚举起点+二分终点. #include<cstdio> #include<cstring> #include<cmath> #include<v ...

  2. 【CodeForces - 660C】Hard Process (尺取 或 二分+滑窗,前缀和预处理)

    题干: You are given an array a with n elements. Each element of a is either 0 or 1. Let's denote the l ...

  3. nalu模式多slice_图像、帧、片、NALU

    图像.帧.片.NALU 是学习 H.264 的人常常感到困惑的一些概念,我在这里对自己的理解做一些阐述,欢迎大家讨论: H.264 是一次概念的革新,它打破常规,完全没有 I 帧.P帧.B 帧的概念, ...

  4. 【每日一题(8)】Mammoth's Genome Decoding CodeForces - 747B

    Mammoth's Genome Decoding CodeForces - 747B The process of mammoth's genome decoding in Berland come ...

  5. Educational Codeforces Round 11C. Hard Process two pointer

    地址:http://codeforces.com/contest/660/problem/C 题目: You are given an array a with n elements. Each el ...

  6. Educational Codeforces Round 39 B Weird Subtraction Process

    传送门 模拟,写的比较土,别吐槽 #include <bits/stdc++.h> using namespace std; typedef long long ll ; typedef ...

  7. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...

  8. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

  9. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

最新文章

  1. Spring Security OAuth笔记
  2. python如何将生成的随机数存入文件中_用python在excel中读取与生成随机数写入excel中...
  3. 【转】jmeter响应结果乱码问题
  4. linux指定内核位置,ARM linux内核启动时几个关键地址
  5. Codeforces Round #263 (Div. 2) D. Appleman and Tree 树形dp
  6. 15 MM配置-BP业务伙伴-定义供应商主记录的编号范围
  7. 【刷题】LOJ 6005 「网络流 24 题」最长递增子序列
  8. 计算机更新过后cad,CAD2022更新了什么?具有哪些新功能?
  9. Android-Binder机制
  10. 南京php吧,利用php爬虫分析南京房价
  11. GBase 8c基础操作
  12. 解析.txt文件入库
  13. 【VBA】Excel拆分表格,并且复制格式
  14. 渗透测试网络攻防--OSINT和被动侦察
  15. 【第3期赠书活动】〖Python 数据库开发实战 - Python与Redis交互篇⑬〗- 综合案例 - 新闻管理系统 - 编辑新闻(编辑角色权限)
  16. 【毒鸡汤】英译毒鸡汤——人生已经如此艰难,何不落井下石
  17. CSS中background-attachment的介绍和用法
  18. C# 淘宝商品微信返利助手开发-(八)微信号对接
  19. 11种全球著名商业分析模型
  20. Unity3D 大型游戏 最后一站 源码 部分重点 GameView-LoginWindow(17)

热门文章

  1. 使用Office Word 2010/2013 发布文章到博客园
  2. 【读书笔记】重要的东西
  3. springboot 闪退。falling back to default profiles: default StandardService - Stopping service [Tomcat]
  4. Android 地图搜索商家,检索关键字(高德地图,百度地图),地址搜索
  5. android Handler Message传递参数,handler子线程和主线程通讯
  6. webpack-dev-server 本地文件 发布 网站 域名 根目录
  7. Java操作Mongo bulkWrite批量入库
  8. 快速入门系列之 Scala 语言 GitChat连接
  9. linux搭建乐网服务器,教你linux搭建web服务器
  10. “export ‘default‘ (imported as ‘echarts‘) was not found in ‘echarts‘