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. vijos 1237 隐形的翅膀

    隐形的翅膀 背景 小杉终于进入了天堂.他看到每个人都带着一双隐形翅膀,他也想要. (小杉是怎么看到的?……) 描述 天使告诉小杉,每只翅膀都有长度,两只翅膀的长度之比越接近黄金分割比例,就越完美. 现 ...

  2. 6、Java并发性和多线程-并发性与并行性

    以下内容转自http://tutorials.jenkov.com/java-concurrency/concurrency-vs-parallelism.html(使用谷歌翻译): 术语并发和并行性 ...

  3. 非常适合新手的jq/zepto源码分析07---ajax的封装

    复习下ajax吧! 1.创建XMLHttpRequest对象 xmlhttp=new XMLHttpRequest(); xmlhttp=new ActiveXObject("Microso ...

  4. MFC ActiveX新增属性页 控件不响应

    在Activex中可以添加自定义的属性页,在新的属性页上添加一个button控件,设置好响应函数后,测试时发现点击button没有响应. 对比之前的主属性页发现,新增属性页的属性“Disabled” ...

  5. fastjson将java list转为json字符串

    1.直接用fastjson的静态方法string JSON.toJSONString(list)方法就行,JSON.toJSONString(list)将java list转为json字符串. 2.t ...

  6. go语言中log包的使用

    package main import ( "github.com/robertkrimen/otto" "log" ) func main() { log.P ...

  7. Android中apk动态载入技术研究(2)android插件化及实现

    了解了android中类载入的前期知识点后,来看看android中DexClassLoader详细的实现     详细载入流程例如以下:     宿主程序会到文件系统比方SD卡中去载入APK[1],然 ...

  8. 2015南阳CCPC C - The Battle of Chibi DP树状数组优化

    C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...

  9. research plan2222

    Thank you for calling. I've been looking forward to this call for a long time.Now, let me introduce ...

  10. 【转】Intent传递数据时,可以传递哪些类型数据?

    在Android应用的开发中,如果我们需要在不同的模块(比如不同的Activity之间)之间传递数据,通常有以下两种方法:1. 利用Intent对象携带数据通过查询Intent/Bundle的API文 ...