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

尺取法,每次遇到0的时候补一个1,直到补完或者越界为止。之后每次从左向右回收一个0点。记录路径用两个指针卡住,每次更新即可。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n, k;
int a[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &n, &k)) {
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
}
int ll = ;
int rr = ;
int al = ;
int ar = ;
int cur = ;
int ans = ;
while() {
if(rr > n) break;
while(rr <= n && cur <= k) {
if(a[rr] == ) {
if(cur == k) break;
cur++;
}
rr++;
}
if(rr - ll > ans) {
ans = rr - ll;
al = ll;
ar = rr - ;
}
while(ll <= rr && a[ll] == ) ll++;
cur--;
ll++;
}
printf("%d\n", ans);
for(int i = ; i <= n; i++) {
if(i >= al && i <= ar) printf("1 ");
else printf("%d ", a[i]);
}
printf("\n");
}
return ;
}

[CF660C]Hard Process(尺取法)的更多相关文章

  1. hdu 6205 card card card 尺取法

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. 5806 NanoApe Loves Sequence Ⅱ(尺取法)

    传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K ...

  3. POJ3061 尺取法

    题目大意:从给定序列里找出区间和大于等于S的最小区间的长度. 前阵子在zzuli OJ上见过类似的题,还好当时补题了.尺取法O(n) 的复杂度过掉的.尺取法:从头遍历,如果不满足条件,则将尺子尾 部增 ...

  4. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  5. CF 701C They Are Everywhere(尺取法)

    题目链接: 传送门 They Are Everywhere time limit per test:2 second     memory limit per test:256 megabytes D ...

  6. nyoj133_子序列_离散化_尺取法

    子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...

  7. Codeforces 676C Vasya and String(尺取法)

    题目大概说给一个由a和b组成的字符串,最多能改变其中的k个字符,问通过改变能得到的最长连续且相同的字符串是多长. 用尺取法,改变成a和改变成b分别做一次:双指针i和j,j不停++,然后如果遇到需要改变 ...

  8. POJ 3061 (二分+前缀和or尺取法)

    题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...

  9. POJ 3320 尺取法,Hash,map标记

    1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...

随机推荐

  1. Spring.net Could not load type from string value

    最近有点懒了啊,都没有按时上来博客园更新下,个人觉得遇到难题的时候在这里留下脚印也亦造福他人,进来 晓镜水月 被项目围的团团转,asp.net MVC项目来的,但是我还是不务正业啊,在弄网络爬虫,这个 ...

  2. 用WebStorm编辑Markdown

    前言[转http://blog.fens.me/webstorm-markdown/] WebStorm是一个非常高效的开发工具,特别对于Web前端的开发.Markdown流行,因为其简化了HTML的 ...

  3. ASP.NET防止用户多次登录的方法

    常见的处理方法是,在用户登录时,判断此用户是否已经在Application中存在,如果存在就报错,不存在的话就加到Application中(Application是所有Session共有的,整个web ...

  4. applicationContext.xml xxx-servlet.xml

    applicationContext.xml是随ContextLoaderListener的加载而执行的,而xxx-servlet.xml是随DispatcherServlet的加载而执行的,在web ...

  5. mybatis处理查询map列表属性为null的问题,而导致查询map无该key对象

    1.常规处理方法(数据库以mysql为例) IFNULL(m.last_use_time,) ) ) as last_lat if判断是否为null,设置一个默认值. 2.前台jsp页面处理,判断是否 ...

  6. php laravel 安装

    windows环境尝试学习一下laravel 1.因为SAE的php版本为5.3,因此最高只能支持到Laravel4.1.x.(Laravel4.2用到了php5.4的trait特性) 以4.1为主. ...

  7. C++堆栈与函数调用

    一.C++程序内存分配 1)在栈上创建.在执行函数时,函数内局部变量的存储单元都在栈上创建,函数结束是,这些存储单元自动被释放.栈内存的分配运算内置于处理器的指令集中,一般采用寄存器来存取,效率很高但 ...

  8. VISO下载地址

    http://pan.baidu.com/share/home?uk=4011207371#category/type=0

  9. CSS3做小三角形

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXgAAAA2CAIAAABC2hVZAAAgAElEQVR4nKzcd3cbV57web+1p20FW8

  10. three.js 简介

    What is Three.js? Let's try to describe it briefly: Three.js is a library that makes WebGL - 3D in t ...