Codeforces 660C Hard Process(尺取法)
题目大概说给一个由01组成的序列,要求最多把k个0改成1使得连续的1的个数最多,输出一种方案。
和CF 676C相似。
#include<cstdio>
#include<algorithm>
using namespace std;
int a[];
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=; i<n; ++i){
scanf("%d",a+i);
}
if(k==){
int ans=,cnt=;;
for(int i=; i<n; ++i){
if(a[i]==){
cnt=;
continue;
}
++cnt;
ans=max(ans,cnt);
}
printf("%d\n",ans);
for(int i=; i<n; ++i){
printf("%d ",a[i]);
}
return ;
}
int i=,j=,tmpn=,tmpk=,ans=,rec;
while(j<n){
if(a[j]==){
while(tmpk==k){
if(a[i]==) --tmpk;
--tmpn;
++i;
}
++tmpk;
}
++tmpn;
if(tmpn>ans){
ans=tmpn;
rec=j;
}
++j;
}
printf("%d\n",ans);
for(int i=; i<=rec-ans; ++i){
printf("%d ",a[i]);
}
for(int i=rec-ans+; i<=rec; ++i){
printf("1 ");
}
for(int i=rec+; i<n; ++i){
printf("%d ",a[i]);
}
return ;
}
Codeforces 660C Hard Process(尺取法)的更多相关文章
- Codeforces 660C Hard Process【二分 Or 尺取】
题目链接: http://codeforces.com/problemset/problem/660/C 题意: 给定0.1组成的数组,可以改变k个0使其为1,问最终可以得到的连续的1的最大长度. 分 ...
- [CF660C]Hard Process(尺取法)
题目链接:http://codeforces.com/problemset/problem/660/C 尺取法,每次遇到0的时候补一个1,直到补完或者越界为止.之后每次从左向右回收一个0点.记录路径用 ...
- Codeforces 958F2 Lightsabers (medium) 尺取法
题目大意: 输入n,m,分别表示人的个数和颜色的个数,下一行输入n个数,对应每个人的颜色,最后一行输入对应每个颜色的人应有的数量: 问是否能找出一个区间,满足条件但有多余的人,输出多余的人最少的个数, ...
- Codeforces 660C - Hard Process - [二分+DP]
题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...
- codeforces 660C Hard Process
维护一个左右区间指针就可以. #include<cstdio> #include<cstring> #include<iostream> #include<q ...
- Codeforces 660 C. Hard Process (尺取)
题目链接:http://codeforces.com/problemset/problem/660/C 尺取法 #include <bits/stdc++.h> using namespa ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
随机推荐
- JavaScript数组排序
JavaScript的sort方法排序是有问题的,我们可以给sort方法传一个参数 function Compare(value1, value2) { //数字排序的函数参数 if (value1 ...
- Swift - 2.3的代码到3.0的转变
分享一下学习新语法的技巧:用Xcode8打开自己的Swift2.3的项目,选择Edit->Convert->To Current Swift Syntax- 让Xcode帮我们把Swift ...
- Ionic环境搭建
stepts npm install -g ionic@beta Make sure you have NodeJS installed. Download the installer here or ...
- codevs 1080 线段树练习
链接:http://codevs.cn/problem/1080/ 先用树状数组水一发,再用线段树水一发 树状数组代码:84ms #include<cstdio> #include< ...
- 与你相遇好幸运,Tippecanoe在Centos下の安装
全新的CentOS 7 x86_64 安装编译工具 yum install -y gcc automake autoconf libtool make yum insyall -y gcc gcc-c ...
- RabbitMQ驱动简单例子
using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Collections.Generic; ...
- maven pom.xml 说明
本文复制于:http://blog.csdn.net/zhuxinhua/article/details/5788546 一.pom.xml示例 <project> <modelVe ...
- 笔记本win7共享WIFI
创建无线网络 (1)netsh wlan set hostednetwork mode=allow ssid=网络名 key=密码 启动承载网络(2)netsh wlan start hostedne ...
- Android在listview添加checkbox实现单选多选操作问题(转)
转自:http://yangshen998.iteye.com/blog/1310183 在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上 ...
- 图说设计模式(UML和设计模式)
https://github.com/me115/design_patterns http://design-patterns.readthedocs.org/zh_CN/latest/index.h ...