题目大概说给一个由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(尺取法)的更多相关文章

  1. Codeforces 660C Hard Process【二分 Or 尺取】

    题目链接: http://codeforces.com/problemset/problem/660/C 题意: 给定0.1组成的数组,可以改变k个0使其为1,问最终可以得到的连续的1的最大长度. 分 ...

  2. [CF660C]Hard Process(尺取法)

    题目链接:http://codeforces.com/problemset/problem/660/C 尺取法,每次遇到0的时候补一个1,直到补完或者越界为止.之后每次从左向右回收一个0点.记录路径用 ...

  3. Codeforces 958F2 Lightsabers (medium) 尺取法

    题目大意: 输入n,m,分别表示人的个数和颜色的个数,下一行输入n个数,对应每个人的颜色,最后一行输入对应每个颜色的人应有的数量: 问是否能找出一个区间,满足条件但有多余的人,输出多余的人最少的个数, ...

  4. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  5. codeforces 660C Hard Process

    维护一个左右区间指针就可以. #include<cstdio> #include<cstring> #include<iostream> #include<q ...

  6. Codeforces 660 C. Hard Process (尺取)

    题目链接:http://codeforces.com/problemset/problem/660/C 尺取法 #include <bits/stdc++.h> using namespa ...

  7. 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 ...

  8. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  9. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

随机推荐

  1. ios电话/密码/验证码/身份证的正则表达式

    // 一 .电话号码正则表达式 -(BOOL)testPhoneNumber:(NSString *)text { NSString *regex =@"(13[0-9]|0[1-9]|0[ ...

  2. September 4th 2016 Week 37th Sunday

    The morning crowned the humble cloud with splendor. 晨光为谦逊的白云披上壮丽的光彩. Humility is a virtue. Many famo ...

  3. mongodb 3.2 用户权限管理配置

    使用mongodb 有段时间了,由于是在内网使用,便没有设置权限,一直是裸奔. 最近有时间,研究了下mongodb 3.2 的用户权限配置,网上有许多用户权限配置的文章,不过大多是之前版本,有些出入, ...

  4. NSOperation使用

    1.继承NSOperation DownLoadImageTask.h #import <Foundation/Foundation.h> #import <UIKit/UIKit. ...

  5. MyBatis mapper文件中的变量引用方式#{}与${}的差别

    MyBatis mapper文件中的变量引用方式#{}与${}的差别 #{},和 ${}传参的区别如下:使用#传入参数是,sql语句解析是会加上"",当成字符串来解析,这样相比于$ ...

  6. iOS - UIButton设置图片文字上图下文排列

    经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButton ...

  7. Loadrunner之API测试

    //API函数 web_submit_data web_custom_request   //支持https请求 web_set_sockets_option("SSL_VERSION&qu ...

  8. I2C学习

    详细的解释: 读写状态机图

  9. Jmeter 提取http请求返回值里json数据参数化方法

    第三方插件下载地址:http://jmeter-plugins.org/downloads/all/ 插件下载后解压:找到JMeterPlugins-Extras.jar,把JMeterPlugins ...

  10. PortSentry是入侵检测工具中配置最简单、效果最直接的工具之一

    https://sourceforge.net/projects/sentrytools/ [root@localhost ~]# tar -xzvf portsentry-1.2.tar.gz [r ...