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 ...
随机推荐
- Asp.net绑定带层次下拉框(select控件)
1.效果图 2.数据库中表数据结构 3.前台页面 <select id="pid" runat="server" style="width:16 ...
- ebay的api的开发技术笔记
使用eBay API基本步骤介绍 要开始使用eBay API,需要如下基本步骤: 1. 注册开发帐号: https://developer.ebay.com/join/Default.aspx ...
- 《iOS开发指南》要改iOS8版本了,听听您的意见?
<iOS开发指南>要改iOS8版本了,听听您的意见?参加问卷同学均可获得智捷课堂50元代金卡一张,同时抽取一名同学赠送即将出版的基于iOS8的<iOS开发指南>一本,欢迎大家填 ...
- iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/
http://zanderzhang.gitcafe.io/2015/09/19/iOS-Andriod百度地图仿百度外卖-饿了么-选择我的地址-POI检索/ 百度外卖选择送货地址: 饿了么选择送货地 ...
- 【学习笔记】【C语言】位运算
1. & 按位与 1> 功能 只有对应的两个二进位均为1时,结果位才为1,否则为0. 2> 举例: 比如9&5,其实就是1001&101=1,因此9&5=1 ...
- JDBC连接MySQL数据库及示例
JDBC是Sun公司制定的一个可以用Java语言连接数据库的技术. 一.JDBC基础知识 JDBC(Java Data Base Connectivity,java数据库连接)是一 ...
- Angular2中的metadata(元数据)
@Attrubute() 从host element 中获得普通(不是@Input)属性对应的值 适用于组件嵌套或指令, 从父组件向子组件传递数据 app.component.ts import {C ...
- 《JavaScript高级程序设计》心得笔记-----第二篇章
第五章 9.Function函数 1) 函数内部有两个特殊的对象: (1) arguments(主要用于保存函数参数,有一个属性callee,这是一个指针,指向拥有argu ...
- 灰度直方算法 C++
#include <string> #include "20140318计算类的面积.cpp" //////////////////////////////////// ...
- Linux platform设备简介
Technorati 标签: Linux platform Linux在2.6内核中,针对一系列设备驱动,提供新的管理框架,成为platform机制,推出的目的,在于隔离驱动的资源和实现,使得 ...