题目链接:

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. 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. 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 枚举 + 差分前缀和

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

  5. Educational Codeforces Round 11 E. 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(A.暴力,B.前缀和,C.贪心)

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

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

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

  8. Educational Codeforces Round 11 B. 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. Co-prime Array 水题

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

随机推荐

  1. 《深入浅出WPF》 学习笔记

    <深入浅出WPF> 序言 1. 什么是WPF    2. 为什么要学习WPF 第一章 XAML概览 1. XAML是什么? 2. XAML有哪些优点 第二章 从零起步认识XAML 1. 新 ...

  2. js 调用php代码

    <?php $test = "var a = ".$_GET['test'].";"; ?> <mce:script type="t ...

  3. C语言中char* 和 char []区别

    想要把丢掉的东西捡起来,还是很辛苦啊,今天我就发现,我连char* 和 char []的区别都不知道. 很多人觉得这两个定义效果一样,其实差别很大.以下是个人的一些看法,有不正确的地方望指正. 本质上 ...

  4. 【学习笔记】【C语言】结构体

    1.定义结构体变量的3种方式 1> 先定义类型,再定义变量(分开定义) struct Student {    int age; }; struct Student stu;  2> 定义 ...

  5. 《锋利的jQuery》心得笔记--One Sections

    第一章 1.    $是jQuery的一个简写形式 2.    在jQuery中无法使用DOM对象的任何方法:比如:$ (“#id”).innerHTML.$ (“#id”).checked, 可以使 ...

  6. Codevs 1039 :数的划分

    总时间限制: 1000ms 内存限制:  65536kB 描述 将整数n分成k份,且每份不能为空,任意两份不能相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5: 1 ...

  7. c++对象内存布局

    这篇文章我要简单地讲解下c++对象的内存布局,虽然已经有很多很好的文章,不过通过实现发现有些地方不同的编译器还是会有差别的,希望和大家交流. 在没有用到虚函数的时候,C++的对象内存布局和c语言的st ...

  8. 麦子学院Android开发Java教程ClassCastException 错误解析

    现在Java编程中经常碰到ClassCastException 错误,ClassCastException 是 JVM 在检测到两个类型间的转换不兼容时引发的运行时异常.此类错误通常会终止用户请求.本 ...

  9. align=absMiddle属性设置

    AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐.AbsMiddle 图像的中间与同一行中最大元素的中间对齐.Baseline 图像的下边缘与第一行文本的下边缘对齐.Bottom 图像的 ...

  10. ASP.NET MVC 及 Areas 简单控制路由

    ASP.NET MVC中怎么去控制路由,这个想关的文章很多,我在这里就是自我总结一下,仅供参考. 1.我们新建一个项目,查看RouteConfig.cs,代码如下: public static voi ...