Educational Codeforces Round 11 C hard process_补题——作为司老大的脑残粉
司老大当时教了一种姿势枚举连续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_补题——作为司老大的脑残粉的更多相关文章
- Educational Codeforces Round 24 CF 818 A-G 补题
6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...
- 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 ...
- Educational Codeforces Round 11 _D
http://codeforces.com/contest/660/problem/D 这个题据说是很老的题了 然而我现在才知道做法 用map跑了1953ms: 题目大意 给你n个点的坐标 求这些点能 ...
- Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...
- Educational Codeforces Round 11
A. Co-prime Array http://codeforces.com/contest/660/problem/A 题意:给出一段序列,插进一些数,使新的数列两两成互质数,求插最少的个数,并输 ...
- 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 ...
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- 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.6 Hive配置metastore
一.配置 1.配置文件 #创建配置文件 [root@hadoop-senior ~]# cd /opt/modules/hive-0.13.1/conf/ [root@hadoop-senior co ...
- Spring Boot 学习系列(07)—properties文件读取
此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 传统的properties读取方式 一般的,我们都可以自定义一个xxx.properties文件,然后在工程 ...
- Git之设置对文件名大小写敏感
关键命令 git config core.ignorecase false
- 点击a标签 跳到当前页面指定div
给标签div设一个id值 <div id="aa"><div> a标签抓取id值,点击跳过去 <a href="#aa">& ...
- Unity3D asset bundle 格式简析
http://blog.codingnow.com/2014/08/unity3d_asset_bundle.html Unity3D 的 asset bundle 的格式并没有公开.但为了做更好的差 ...
- spark sql 的metastore 对接 postgresql
本教程记录 spark 1.3.1 版本的thriftserver 的metastore 对接 postgresql postgresql 的编译,参考:http://www.cnblogs.com/ ...
- Tomcat - ClassFormatException的解决方法
问题与分析 在使用Tomcat7运行web项目时报错如下: 严重: Compilation error org.eclipse.jdt.internal.compiler.classfmt.Class ...
- Zynq7000开发系列-3(Xilinx交叉编译环境搭建)
一.前言 上一篇文章说了,在开发之前必须先搭建起交叉编译环境,于是这里我们就介绍一下环境的搭建过程. 其实在所安装的Vivado HLx 2016.4中就包含了Xilinx SDK,在该SDK上即可开 ...
- [UOJ22]外星人
题解 首先可以发现有效果的\(a_i\)大小一定是递减的,而且一定小于等于当前值 所以我们可以从大到小考虑每个\(a_i\),当确定了一个有效果的\(a_i\)时,\((a_i,x]\)的数都可以随意 ...
- 修正 FreeBSD 字体锯齿问题
如果你给 FreeBSD 安装完图形界面,一登录就被满屏幕不论中英全是锯齿且残缺不堪入目的文字吓了一跳,那一定是安装了文泉驿字体.先不必急着卸载文泉驿,只需简单修改相关配置即可恢复正常显示.这是因为文 ...