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. 时间插件,js格式化,js某月天数,js某月最后一天日期

    //时间格式化 Date.prototype.format = function(fmt) { var o = { "M+": this.getMonth() + 1, //月份 ...

  2. matlab初试牛刀__小练习

    % T1 % 最好还是设 h=2 D=1 clear,clc; h=2;D=1; x=-2*D:0.01:2*D; y=h*(x>D)+h/D.*x.*(abs(x)<=D)-h*(x&l ...

  3. SharePoint 2013 JavaScript 对象推断用户权限

    场 景 最近有个场景,推断当前用户对项目有没有编辑权限,使用JavaScript完毕.弄了好久才弄出来.分享一下,有须要的自行扩展吧,详细例如以下: 代 码 function getPermissi ...

  4. Chrome 消息机制

    Chrome浏览器扩展开发系列之十四:本地消息机制Native messaging 时间:2015-10-08 16:17:59      阅读:1560      评论:0      收藏:0    ...

  5. rel='canonical'

    rel='canonical' <!DOCTYPE html><html><head> <meta charset="utf-8"/> ...

  6. 【SWUST626】分数分解

    Position: * http://acm.swust.edu.cn/problem/0626/ * List SWUST626 分数分解 List Description Input Output ...

  7. 【POJ 3614】 Sunscreen

    [题目链接] http://poj.org/problem?id=3614 [算法] 将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜 [代码] #include <algorithm& ...

  8. MSP430 WDT

    MSP430 WDT 有两种模式:1,看门狗  2,定时器 我们这次只用定时器模式,注意有两个决定定时时间的地方:1,时钟源选择  2,间隔时间选择 时钟源可以为:SMCLK 或者 ACLK 时间间隔 ...

  9. 创建 /dev/video0 节点 (转载)

    转自:http://blog.csdn.net/linuxmake/article/details/8208464 最近做摄像头驱动,发现没有 /dev/video0节点,经过查看发现是内核编译时没有 ...

  10. Vue解决移动端localhost无数据问题

    正常web端调用后台接口时使用localhost或者ip都能访问后台数据,但是在移动端上使用localhost却无法访问后台数据 这时候需要把localhost改成ip就可以在移动端上访问后台数据了