Codeforces 660 C. Hard Process (尺取)
题目链接: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 (尺取)的更多相关文章
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- 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 ...
- 【尺取或dp】codeforces C. An impassioned circulation of affection
http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- 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 ...
- 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, ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...
- Codeforces - 6E - Exposition - 尺取
https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...
- Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取
https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...
随机推荐
- web项目路径问题
路径 相对路径 URL中第一个字符不为“/” request.getRequestDispatcher("b"); 相对于该代码所在 ...
- taobao
taobao */--> UP | HOME taobao Table of Contents 1 taobao 1 taobao 欣然小铺 Date: 2013-09-25 Wen Autho ...
- string tips
1. .net文档中说,split 比 indexOf 消耗更多的性能.在as3中经过本人测试,这个结论一样成立.而且,字符串越长,split和indexOf的差距就越明显!!所以,能用indexOf ...
- 添加navbar以及上面的左右按钮代码
UINavigationBar *navBar = [[UINavigationBaralloc] initWithFrame:CGRectMake(0, 0, 824, 44)]; navBar.b ...
- 【转】Ubuntu搭建Eclipse+JDK+SDK的Android
原文网址:http://blog.csdn.net/ithomer/article/details/6960989 今晚重装Ubuntu系统,重新安装了一套eclipse+jdk+SDK的Androi ...
- Android 手写Binder 教你理解android中的进程间通信
关于Binder,我就不解释的太多了,网上一搜资料一堆,但是估计还是很多人理解的有困难.今天就教你如何从 app层面来理解好Binder. 其实就从我们普通app开发者的角度来看,仅仅对于androi ...
- Symfony2学习笔记之表单
对于一个Web开发者来说,处理HTML表单是一个最为普通又具挑战的任务.Symfony2集成了一个Form组件,让处理表单变的容易起来.在这一节里,我们将从基础开始创建一个复杂的表单,学习表单类库中最 ...
- SmartGit STUDY
Git Concepts This section helps you to get started with Git and gives you an understanding of the fu ...
- Android 所有版本区别总结(转)
Android 1.0 第一版商用操作系统 Android 1.1 更新了部分API,新增一些功能,修正了一些错误,同时增加com.google.android.maps包 Android 1.5 智 ...
- Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104
Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104 一.WINVER Compile result: WINVER not d ...