Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接:
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 前缀和+二分的更多相关文章
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- 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 ...
- Educational Codeforces Round 11
A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...
- Educational Codeforces Round 61 C 枚举 + 差分前缀和
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Educational Codeforces Round 11 B. Seating On Bus 水题
B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...
- 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 ...
随机推荐
- SQL Server 日志清除
在SqlServer中清除日志就必须在简单模式下进行,等清除动作完毕再调回到完全模式. *[DataBaseName]要压缩日志的数据库名称. 设置数据库模式为简单模式 ALTER DATABASE ...
- [javascript|基本概念]学习笔记
1/语法 a.区分大小写 b.标识符(首字符必须是字母/"_"/"$",其他可为字母/"_"/"$"/数字,不能用关键字 ...
- Firefox 与 IE 对Javascript和CSS的区别
1. document.formName.item("itemName") 问题 说明:IE下,可以使用document.formName.item("itemName& ...
- JPA SQL 的复杂查询createNamedQuery
@NamedNativeQueries({ @NamedNativeQuery( name = "getNativeNutShellInfo", //需要调用的name query ...
- Objective-C中字典的使用方法总结
在Objective-C中提供了两个类来实现字典,即NSDictionary和NSMutableDictionary.其中,NSMutableDictionary是NSDictionary的子类,它继 ...
- windows程序消息机制(Winform界面更新有关)
windows程序消息机制(Winform界面更新有关) 转自:http://www.cnblogs.com/blosaa/archive/2013/05/31/3109586.html 1. Win ...
- 下拉刷新--第三方开源--PullToRefresh
效果预览图: 下载地址:https://github.com/chrisbanes/Android-PullToRefresh activity_main.xml: <RelativeLayou ...
- aspx返回json数据
JQuery.getJSON 从aspx页面返回JSON数据 . -- ::| 分类: asp.net |举报|字号 订阅 . 发送请求的WebForm1.aspx <%@ Page Langu ...
- Oracle bbed 实用示例-----File Header Reset
一.查看当前环境 1.1 当前控制文件中的SCN号 [oracle@ora10 ~]$ sqlplus /nolog SQL :: Copyright (c) , , Oracle. All righ ...
- python2.7之乱码问题(直接从我的csdn上复制粘贴过来的。。。)
学习python一段时间了,一直没有写过博客.就从今天开始吧! python 3之后当然不存在乱码问题了.python 2的乱码问题有时就有点头疼了.(代码均为在windows下测试) 示例:保存为t ...