Educational Codeforces Round 11 C. Hard Process 前缀和+二分

时间:2022-09-03 22:22:01

题目链接:

http://codeforces.com/contest/660/problem/C

题意:

将最多k个0变成1,使得连续的1的个数最大

题解:

二分连续的1的个数x。用前缀和判断区间[i,i+x-1]里面0的个数是否小于等于k。

代码:

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std; const int maxn=3e5+; int n,k;
int sum[maxn],arr[maxn]; bool ok(int x,int &pos){
for(int i=;i+x<=n;i++){
if(x-(sum[i+x]-sum[i])<=k){
pos=i+;
return true;
}
}
return false;
} int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",arr+i);
}
sum[]=;
for(int i=;i<=n;i++){
sum[i]=sum[i-]+arr[i];
}
int l=k,r=n+,pos;
while(l+<r){
int mid=l+(r-l)/;
if(ok(mid,pos)) l=mid;
else r=mid;
}
ok(l,pos);
for(int i=pos;i<pos+l;i++){
arr[i]=;
}
printf("%d\n",l);
for(int i=;i<n;i++) printf("%d ",arr[i]);
printf("%d\n",arr[n]);
return ;
}

Educational Codeforces Round 11 C. Hard Process 前缀和+二分的更多相关文章

  1. Educational Codeforces Round 11 C&period; Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

  2. Educational Codeforces Round 11——C&period; Hard Process(YY)

    C. Hard Process time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Educational Codeforces Round 11

    A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...

  4. Educational Codeforces Round 61 C 枚举 &plus; 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

  5. Educational Codeforces Round 11 E&period; Different Subsets For All Tuples 动态规划

    E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...

  6. Educational Codeforces Round 21&lpar;A&period;暴力&comma;B&period;前缀和&comma;C&period;贪心&rpar;

    A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  7. Educational Codeforces Round 11 D&period; Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  8. Educational Codeforces Round 11 B&period; Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

  9. Educational Codeforces Round 11 A&period; Co-prime Array 水题

    A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...

随机推荐

  1. Transient的作用

    1:transient的作用及其使用方法 当一个对象实现类Serilizable接口,那么这个类就可以被序列化,java的这种序列化的模式为开发者提供了很多的便利. 然而在实际开发中,我们常常遇到这样 ...

  2. Python之路-python(set集合、文本操作、字符编码 )

    一.集合操作(set)                                                                                          ...

  3. &lpar;转载&rpar; jQuery 页面加载初始化的方法有3种

    jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...

  4. Debug Intro

    The ABAP Debugger is used tool to execute and analyze programs line by line. Using it we can check t ...

  5. 1602A液晶

    液晶显示屏中,1602型算是比较简单的一种,据说和12864还是全兼容的.这两天学习的结果如下.一.1602里的存储器有三种:CGROM.CGRAM.DDRAM.CGROM保存了厂家生产时固化在LCM ...

  6. MySQL优化三(InnoDB优化)

    body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10 ...

  7. 201521123104《JAVA程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 1. 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出 ...

  8. Oracle数据库应用

    Oracle数据库应用 一:.Oracle数据库应用知识 二:表空间和用户权限管理 表空间: 表空间是数据逻辑结构的一个重要组件,表空间可以存放各种应用对象,如表,索引.而每个表空间由一个或者多个数据 ...

  9. JAVA 语言如何进行异常处理,关键字: throws&comma;throw&comma;try&comma;catch&comma;finally分别代表什么意义? 在try块中可以抛 出异常吗?

    Java通过面向对象的方法进行异常处理,把各种不同的异常进行分类, 并提供了良好的接口.        在 Java中,每个异常都是一个对象,它是 Throwable 类或其它子类的实例.当一个方法出 ...

  10. LNAMP服务器环境(源码安装)

    在安装前先看下它们安装时所需要的依赖库:http://www.cnblogs.com/fps2tao/p/7699448.html 1.nginx源码安装 下载:http://nginx.org/en ...