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里IN的用法以及优化
1.in后条件不多,可以考虑主表建索引,或用union all 代替 2. in 和 exists的区别: 如果子查询得出的结果集记录较少,主查询中的表较大且又有索引时应该用in, 反之如果外层的主查 ...
- 服务器无法播放flv格式的视频解决办法
浏览某个网站时播放视频可能会出现下面的情况: 其实原因很简单,因为国内大多都是Win2003的主机 .默认是没有指定输出FLV这种格式的. 虽然FTP里面可以看见,但无法通过http访问,也就无法播放 ...
- MVC 构造
// // View.h // UI5_HomeWork // // Created by zhangxueming on 15/7/2. // Copyright (c) 2015年 zhangxu ...
- 简单解析依赖注入(控制反转)在Spring中的应用
IoC——Inversion of Control 控制反转DI——Dependency Injection 依赖注入 大家都知道,依赖注入是Spring中非常重要的一种设计模式.可能很多初学者 ...
- laravel步骤 (我是新手)
1/需要一个wnmp之类的虚拟服务器 2/创建路由 php artisan make:route routes Route::group(['middleware' => ['web','a ...
- String 两种实例化方式的区别
package com.java1234.chap03.sec08; public class Demo3 { public static void main(String[] args) { //1 ...
- 玄机宝盒v1.6.1.1
最新版本:玄机宝盒v1.6.1.1 玄机宝盒v1.6.1.1 04-14/2016 给你的将是无与伦比的体验http://bbs.msdn5.com/thread-15-1-1.html(出处: 玄机 ...
- java 环境变量设置
JAVA_HOME C:\Program Files\Java\jdk1.7.0 PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; CLASSPATH .;%JAV ...
- 使用Eclipse开发,Java Compiler中Annotation Processin不出现的解决方案
第一步:在Eclipse菜单栏中点击Help,在点击inatall New Software 第二步:在Work with中找到 Juno - http://download.eclipse.org/ ...
- Oracle RAC Failover
Oracle RAC 同时具备HA(High Availiablity) 和LB(LoadBalance). 而其高可用性的基础就是Failover(故障转移). 它指集群中任何一个节点的故障都不会 ...