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. 5、Java并发性和多线程-相同线程

    以下内容转自http://tutorials.jenkov.com/java-concurrency/same-threading.html(使用谷歌翻译): 相同线程(同一线程)是一种并发模型,其中 ...

  2. 26、Java并发性和多线程-线程池

    以下内容转自http://ifeve.com/thread-pools/: 线程池(Thread Pool)对于限制应用程序中同一时刻运行的线程数很有用.因为每启动一个新线程都会有相应的性能开销,每个 ...

  3. iOS xmpp协议实现聊天之openfire的服务端配置(二)

    本篇主要说一下怎样利用命令行来正确配置MySql. 首先打开终端: 1.为mysql起一个别名 alias mysql=/usr/local/mysql/bin/mysql 2.创建mysql的管理员 ...

  4. 改动grub默认启动顺序

    grub如今有两个版本号,一个grub,一个grub2,两个版本号的操作不太一样. 装centos的朋友非常有可能是grub.我电脑装的是ubuntu14.04,为grub2.我演示grub2的过程. ...

  5. struts2 一个CRUD的BaseAction

    在struts2 in action中所见,这样封装后省去了大部分crud反复代码.尽管还不能理悟.先记下来. abstract class BaseAction extends ActionSupp ...

  6. linux 统计 文件夹信息

    ls -lR|grep "^-"|wc -l Linux 统计某个字符串出现的次数 - ywl925 - 博客园 https://www.cnblogs.com/ywl925/p/ ...

  7. ios9--UIImageView的帧动画

    // // ViewController.m // 05-UIImageView的帧动画 // #import "ViewController.h" @interface View ...

  8. 曼哈顿距离(坐标投影距离之和)d(i,j)=|X1-X2|+|Y1-Y2|.

    曼哈顿距离(坐标投影距离之和)d(i,j)=|X1-X2|+|Y1-Y2|. 我们可以定义曼哈顿距离的正式意义为L1-距离或城市区块距离,也就是在欧几里德空间的固定直角坐标系上两点所形成的线段对轴产生 ...

  9. XAML实例教程系列 - 命名空间(NameSpace) 三

    XAML实例教程系列 - 命名空间(NameSpace) 2012-05-28 14:14 by jv9, 2205 阅读, 10 评论, 收藏, 编辑 上一篇曾提及XAML中,每个对象元素的声明是对 ...

  10. git ldap

    https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md ldap : enabled : true host : 'ope ...