D. Sea Battle
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.

Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").

Galya has already made k shots, all of them were misses.

Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

It is guaranteed that there is at least one valid ships placement.

Input

The first line contains four positive integers nabk (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.

The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

Output

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

In the second line print the cells Galya should shoot at.

Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 ton, starting from the left.

If there are multiple answers, you can print any of them.

Examples
input
5 1 2 1
00100
output
2
4 2
input
13 3 2 3
1000000010001
output
2
7 11
Note

There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.

题意:1*n的矩阵上,a条船,每条都是b的长度,已经开了k炮,每个格子只能被一条船占据。问最少再开多少炮能至少击中一条船,输出这几炮的位置。

比赛是以为搞不出来,结果给搞出来了,开心!!!

思路:抽象一下,也就是说,在序列中某些位置加上1后,序列中能放下的长度b的0序列的个数<=a-1。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 200005 struct Seg
{
int l,r,dis;
} seg[N];
bool cmp(Seg a,Seg b)
{
return a.dis>b.dis;
} int main()
{
int n,a,b,k;
char str[N];
scanf("%d%d%d%d",&n,&a,&b,&k);
scanf("%s",str);
int st=,en=,p=,cnt=;
while(p<n)
{
if(str[p]=='')
{
en=p-;
Seg se;
se.l=st;
se.r=en;
se.dis=en-st+;
if(se.l<=se.r)
seg[cnt++]=se;
while(str[p]=='')
p++;
st=en=p;
}
if(str[n-]==''&&p==n-)
{
en=n-;
Seg se;
se.l=st;
se.r=en;
se.dis=en-st+;
if(se.l<=se.r)
seg[cnt++]=se;
}
p++;
}
sort(seg,seg+cnt,cmp);
int ans[N],cnta=;
int cntt=;
for(int i=; i<cnt; i++)
for(int j=seg[i].l+b-; j<=seg[i].r; j+=b)
{
if(cntt>=a-)
ans[cnta++]=j+;
else
cntt++;
}
printf("%d\n",cnta);
for(int i=; i<cnta; i++)
{
printf("%d",ans[i]);
if(i==cnta-)
printf("\n");
else
printf(" ");
}
return ;
}

codeforces_738D的更多相关文章

随机推荐

  1. Linux下Ubuntu 操作系统 部署

    1.1 先更新系统 环境 更新命令为: apt-get update 1.2 安装jdk 安装JDK命令为:sudo apt-get install o penjdk-7-jdk 1.3 安装tomc ...

  2. Java的23种设计模式(转)

    设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 毫无疑问,设计模式于 ...

  3. Shine.js实现动态阴影效果

    Shine.js 是一个用于实现美丽阴影的 JS 库. 特性 1.可动态旋转光的位置,投影出不同的阴影效果 2.可定制的阴影, 3.没有库依赖关系,AMD兼容使用基于内容的文本或框阴影 4.在浏览器支 ...

  4. easyUI中的layout

    Layout 通过$.fn.layout.defaults能够重写Layout. layout是一个具有五个区域的容器.仅仅有中间区域面板是必须的,其余的都是边界面板.每个边界面板都能够通过拖动它的边 ...

  5. jquery操作删除元素

    通过 jQuery,可以很容易地删除已有的 HTML 元素. 删除元素/内容 如需删除元素和内容,一般可使用以下两个 jQuery 方法: remove() - 删除被选元素(及其子元素) empty ...

  6. YTU 2782: 用数字造数字

    2782: 用数字造数字 时间限制: 1 Sec  内存限制: 128 MB 提交: 191  解决: 160 题目描述 输入一个3位以上的整数,求其中最大的数字最小的数字之间的差.例如:输入8729 ...

  7. 洛谷P1045 麦森数

    题目描述 形如2^{P}-12 ​P ​​ −1的素数称为麦森数,这时PP一定也是个素数.但反过来不一定,即如果PP是个素数,2^{P}-12 ​P ​​ −1不一定也是素数.到1998年底,人们已找 ...

  8. java事件处理机制(自定义事件)

    java中的事件机制的参与者有3种角色: 1.event object:事件状态对象,用于listener的相应的方法之中,作为参数,一般存在与listerner的方法之中 2.event sourc ...

  9. bzoj2194

    http://www.lydsy.com/JudgeOnline/problem.php?id=2194 卷积... 卷积并不高深,其实卷积就是两个多项式相乘的系数,但是得满足一点条件,就是f[n]= ...

  10. Java使用Cipher类实现加密,包括DES,DES3,AES和RSA加密

    一.先看一个简单加密,解密实现 1.1 加密 /** * content: 加密内容 * slatKey: 加密的盐,16位字符串 * vectorKey: 加密的向量,16位字符串 */ publi ...