题目链接:http://codeforces.com/problemset/problem/660/C

尺取法

 #include <bits/stdc++.h>
using namespace std;
int main()
{
static int num[int(3e5 + )];
int n, k;
scanf("%d %d", &n, &k);
for(int i = ; i <= n; ++i) {
scanf("%d", num + i);
}
int l = , res = , cnt = , flagl = , flagr = -;
for(int i = ; i <= n; ++i) {
if(num[i]) {
if(i - l + > res) {
res = i - l + , flagl = l, flagr = i;
}
} else {
cnt++;
while(cnt > k && l <= i) {
if(!num[l++])
--cnt;
}
if(i - l + > res) {
res = i - l + , flagl = l, flagr = i;
}
}
}
for(int i = flagl; i <= flagr; ++i)
num[i] |= ;
printf("%d\n", res);
for(int i = ; i <= n; ++i) {
printf("%d%c", num[i], i == n ? '\n': ' ');
}
return ;
}

Codeforces 660 C. Hard Process (尺取)的更多相关文章

  1. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  3. 【尺取或dp】codeforces C. An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  4. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  5. B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

  7. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  8. Codeforces - 6E - Exposition - 尺取

    https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...

  9. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

随机推荐

  1. 51nod1274 最长递增路径

    将边排序后dp一下就可以了. #include<cstdio> #include<cstring> #include<cctype> #include<alg ...

  2. WEBUS2.0 In Action - 搜索操作指南 - (3)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...

  3. IntelliJ IDEA使用总结篇

    解决控制台中文乱码的问题: 1.windows下改intellij安装目录下bin\idea.exe.vmoptions文件 加上 -Dfile.encoding=UT 2.设置IDEA server ...

  4. 2015-10-11 Sunday 晴 ARM学习

    基础的知识看得差不多了,linux系统相关的,最主要是c语言基础知道,还有linux系统编程,网络编程socket等相关的.这些内容最最基础的看完了,接下来我在考虑看什么呢?是看ARM以及驱动编程系列 ...

  5. 一:ZooKeeper简介

    一:背景                --->随着互联网技术的高速发展,企业对计算机系统的计算,存储能力要求越来越高,最简单的明证就是出现一些诸如:高并发,海量存储这样的词汇.在这样的背景下, ...

  6. RAC 数据库的启动与关闭

    RAC数据库与单实例的差异主要表现在多个实例通过集群件来统一管理共享的资源.因此原有的单实例的管理方式,如数据库.监听器等的关闭启动等可以使用原有的方式进行,也可以通过集群管理工具,命令行来集中管理, ...

  7. MVC2.0前置

    .NET MVC执行过程: 1.网址路由比对 2.执行Controller与Action 3.执行View并返回结果 在使用MVC中是由IgnoreRoute()辅助方法对比成功的,会导致程序直接跳离 ...

  8. Android应用性能优化之使用SQLiteStatement优化SQLite操作

    平常在做Android数据库操作时,都是用的execSQL之个方法. 今天偶然发现了SQLiteStatement这个类.让我想起了在做Java Web开发写JDBC的代码时Prestatement这 ...

  9. vs2012编译出错“LC.exe”已退出解决方法

    “LC.exe”已退出,代码为 -1. 解决方法: 将项目Properties下的licenses.licx文件删除,重新编译即可.

  10. python27+django1.9添加api

    我们进入Python的交互 shell 并使用Django提供的API.要进入Python shell,使用python manage.py shell 使用这个而不是简单的输入"pytho ...