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. Ubuntu 16.04安装WPS

    1.下载 http://community.wps.cn/download/ 根据需要对应版本进行下载deb包. 2.安装 sudo dpkg -i wps-office_10.1.0.5672~a2 ...

  2. 微軟将弃用 System.Data.OracleClient

    http://www.cnblogs.com/WizardWu/archive/2010/05/17/1737009.html 微軟将从 .NET 4 以后的版本弃用 System.Data.Orac ...

  3. load函数

    load函数的作用 1.load函数的作用是,从server获取数据,而且把数据放到指定的元素(通常是div元素)中. 2.说的再具体一些就是,把获取到的数据插入到当前文档的某个div元素中. ser ...

  4. squid配置透明代理

    搞了半个月的squid普通代理和透明代理最终差点儿相同了!! squid配置透明代理主要有两步.见图: 第一个基本的步骤:设置client默认网关,让默认网关指向squid代理server water ...

  5. Java Map 怎样实现Key 的唯一性?

    大家都知道.在Map和Set不可存在反复元素? 可是对于内部的细节我们并不了解.今天我们就一块来 探讨一下! 1 对于 HashMap  HashSet 他们的底层数据结构的实现是:维护了一张  Ha ...

  6. 02-JZ2440裸机学习之GPIO实验【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/54910717 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  7. servlet3.0 JQuary Ajax基本使用

    servlet3.0 没有web.xml文件,需要使用注解进行配置. js: $(document).ready(function(){ $("#btn").click(funct ...

  8. MAC地址 初识

    MAC地址 即物理地址/硬件地址 地址长度为48位,6字节. 格式为:00-23-5A-15-99-42 一个网卡对应一个MAC地址(比如笔记本,有线网卡有一个MAC地址,无线网卡也有一个MAC地址) ...

  9. struts2什么情况用#和EL表达示

    1:struts2标签使用中,什么时候用#,什么时候可以不用# 值栈中的对象的不使用#,非值栈中的对象使用#如果不理解值栈的作用,简单点理解:当前action,或者处于action链中的action所 ...

  10. Gym - 101982A 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) A. Exam

    题面 题意:你和朋友一起做了n道判断题,现在你知道你们两的答案,也知道你朋友对了k个,问你至少对了几个 题解:假设你和朋友n个答案都一样,那你是不是也对了k个,假设你和朋友有1个答案不一样,是不是,你 ...