司老大当时教了一种姿势枚举连续K个0,说实话当时比赛写这题完全蒙了 纵然后来知道思路还是写了一段时间 真的是。。

题目大意  n长度的序列,由0 1构成 我们可以改变 k个0为1 求可以得到的最长连续1序列的长度

既然求连续1 我们贪心连续k个0 枚举端点 左端点0设置为0 右端点0设置为 n+1 中间统计一下 最长长度和改变的0的位置就OK了

 #include<cstdio>
#include<map>
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<climits>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef __int64 int64;
const ll mood=1e9+;
const int64 Mod=;
const double eps=1e-;
const int MAXN=;
const double PI=acos(-1.0);
inline void rl(ll&num){
num=;ll f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')num=num*+ch-'',ch=getchar();
num*=f;
}
inline void ri(int &num){
num=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')num=num*+ch-'',ch=getchar();
num*=f;
}
int getnum()//相邻的个位整数输入 如想分别保存1234 输入连续的1234 a[i]=getnum();就可以实现
{
char ch=getchar();
while((ch<'' || ch>'') && ch!='-')
ch=getchar();
return (ch-'');
}
inline void out(int x){ if(x<) {putchar('-'); x*=-;}if(x>) out(x/); putchar(x%+''); }
int a[],b[];
int main()
{
int n,k;
ri(n),ri(k);
int len=,tem;
for(int i=;i<=n;i++)
{
ri(b[i]);
if(!b[i]) a[++len]=i;
}
if(k>=len){
out(n);putchar('\n');
for(int i=;i<=n;i++)
{
putchar('');
if(i!=n)putchar(' ');
}
putchar('\n');
}
else{
a[]=;a[len+]=n+;
int mx=-,l,r;
for(int i=;i-+k<=len;i++)
{
if(mx<a[i+k]-a[i-]-)
{
mx=a[i+k]-a[i-]-;
l=a[i-]+;
r=a[i+k]-;
}
}
out(mx);putchar('\n');
for(int i=;i<=n;i++)
{
if(i>=l&&i<=r)putchar('');
else out(b[i]);
if(i!=n)putchar(' ');
}
}
return ;
}

要有思想

至于廷伟菊苣说的dp和线段树姿势还不会。。。

Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉的更多相关文章

  1. Educational Codeforces Round 24 CF 818 A-G 补题

    6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...

  2. Educational Codeforces Round 11 A. Co-prime Array 水题

    A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...

  3. Educational Codeforces Round 11 _D

    http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...

  4. Educational Codeforces Round 11 C. Hard Process 前缀和+二分

    题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...

  5. Educational Codeforces Round 11

    A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...

  6. Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划

    E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...

  7. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  8. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

  9. Educational Codeforces Round 11 B. Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

随机推荐

  1. 【Linux学习】Linux用户管理1—用户查询指令、用户切换

    Linux用户管理1-用户查询指令.用户切换 一.用户查询指令 who: 查看当前在线用户情况 -a:显示所有用户的所有信息 -m:显示运行该程序的用户名,和"who am I"的 ...

  2. 01 mybatis框架整体概况(2018.7.10)-

    01 mybatis框架整体概况(2018.7.10)- F:\廖雪峰 JavaEE 企业级分布式高级架构师课程\廖雪峰JavaEE一期\第一课(2018.7.10) maven用的是3.39的版本 ...

  3. PHP中正则表达式学习及应用(三)

    正则表达式中的“模式修正符” 1.运算顺序    2.模式修正符 i 正则内容在匹配时候不区分大小写(默认是区分的) 例如: <?php $mode="/[a-z]/i"; ...

  4. STL中的vector实现邻接表

    /* STL中的vector实现邻接表 2014-4-2 08:28:45 */ #include <iostream> #include <vector> #include  ...

  5. UVA12504【C++STL运用】

    雨巨的UVA的C++题集英文真长- 题意: 有两本字典,第一行是旧字典,第二行是新字典. 每行不超过100个字符,没有空格,两本字典都可以是空的: 新key:+ 缺key:- 值变 :* 思路: 具体 ...

  6. Type中的3个bool属性: IsGenericType , IsGenericTypeDefinition , IsGenericParameter

    首先说下 IsGenericType 用3个实例说明: typeof(DateTime).IsGenericType : false typeof(List<int>).IsGeneric ...

  7. ADO winform注册

    前面我们了解了如何实现登录,现在.我们来讨论如何实现注册功能,注册其实就是 通过程序,往数据库中新增数据.首先我们同样连接到数据库,同上页一样创建连接,然后 打开连接.之后我们就要去获取我们输入到文本 ...

  8. 关于在linux系统环境下解压rar压缩文件

    如果在zip压缩文件,可以使有unzip来进行解压.可以直接使用yum进行下载. 但如果是rar类型压缩文件,使用yum就可能无法直接安装. 要到网址:https://www.rarlab.com/d ...

  9. JDBC连接池一 自定义连接池

    package com.mozq.jdbc; import java.io.IOException; import java.io.InputStream; import java.sql.Conne ...

  10. cmd,bat和dos的区别

    区别 dos是磁盘操作系统(Disk Operating System),是个人计算机上的一类操作系统. bat是DOS命令,在任何dos环境下都可以使用. bat文件是dos下的批处理文件,批处理文 ...