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 bconsecutive 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 to n, 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.

题目大意:有a个长为b的船,藏在连续的0里,求至少在0里射击枪,一定能击中至少一艘船,并输出射击的位置

思路:一开始把题想复杂了,以为要对b=1的情况进行特判,其实用一种就行。

  建立结构体z,表示每一段连续的0的左端点l,右端点r,其中0的个数len,以及能放的船数num=len/b,将所有的num+起来为sum,与a比较,由于只要确保能击中就行,因此只需要攻击sum-a+1次,就一定能攻击到;对每一个z,从他的l+b-1处开始攻击(这个位置的前面不能藏一艘船),每次+b攻击,直到攻击够sum-a+1次为止。

代码:

 #include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 200005
#define inf 1e18+5
typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
int i,j,k,m,n,t,cc,a,b,ans;
int s[N],h[N];
struct z{
int l;
int r;
int len;
int num;
}z[N];
int main()
{
while(scanf("%d%d%d%d",&n,&a,&b,&k)!=EOF){
ans=;
k=n-k;
j=;
m=;
cc=;
s[]=-;
getchar();
for(i=;i<=n;i++){
scanf("%c",&s[i]);
if(s[i]==''&&s[i-]!=''){
z[j].l=i;
}
if(s[i]==''&&s[i-]==''){
z[j].r=i-;
z[j].len=z[j].r-z[j].l+;
z[j].num=z[j].len/b;
cc+=z[j].len/b;
j++;
}
if(i==n&&s[i]==''){
z[j].r=i;
z[j].len=z[j].r-z[j].l+;
z[j].num=z[j].len/b;
cc+=z[j].len/b;
j++;
}
}
/* if(b==1){
if(k==cc){
for(i=0;i<j;i++){
for(int i1=z[i].l;i1<=z[i].r;i1++){
h[m]=i1;
m++;
}
}
ans=m;
}
else{
ans=k-a+1;
for(i=0;i<j;i++){
for(int i1=z[i].l;i1<=z[i].r;i1++){
h[m]=i1;
m++;
if(m==ans) break;
}
if(m==ans) break;
}
}
}
else */ {
/*if(a==cc){
for(i=0;i<j;i++){
if(z[i].num){
for(int i1=z[i].l+b-1;i1<=z[i].r+b-1;i1+=b){
h[m]=i1;
m++;
}
}
}
ans=m;
}
else */{
ans=cc-a+;
for(i=;i<j;i++){
if(z[i].num){
for(int i1=z[i].l+b-;i1<=z[i].r;i1+=b){
h[m]=i1;
m++;
if(m==ans) break;
}
}
if(m==ans) break;
}
}
}
// for(i=0;i<j;i++) printf("%d %d \n",z[i].l,z[i].r); printf("%d\n",ans);
for(i=;i<m;i++){
if(i!=m-) printf("%d ",h[i]);
else printf("%d\n",h[i]);
}
} return ;
}

Codeforces #380 div2 D(729D) Sea Battle的更多相关文章

  1. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  2. Codeforces 729D Sea Battle(简单思维题)

    http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html   原 题意:海战 ...

  3. Codeforces #380 div2 E(729E) Subordinates

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces #380 div2 C(729C) Road to Cinema

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces #380 div2 B(729B) Spotlights

    B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #380 (Div. 2)D. Sea Battle

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

随机推荐

  1. order_by_、group_by_、having的用法区别

    写于 2012-11-20 22:14  doc文档上. Having 这个是用在聚合函数的用法.当我们在用聚合函数的时候,一般都要用到GROUP BY 先进行分组,然后再进行聚合函数的运算.运算完后 ...

  2. freeregex-0.01 使用文档

    -- freeregex,简化字符串处理 freeregex使用大体分为两个部分: 正则确定 功能操作 正则确定:共有EMAIL.IP等静态属性:anyOf(String regex)静态方法 :和o ...

  3. Android Studio开发基础之自定义View组件

    一般情况下,不直接使用View和ViewGroup类,而是使用使用其子类.例如要显示一张图片可以用View类的子类ImageView,开发自定义View组件可分为两个主要步骤: 一.创建一个继承自an ...

  4. js escape

    JS转义 escape().encodeURI().encodeURIComponent()区别详解 JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,e ...

  5. Ubuntu 查询 so 归属的 package

    . . . . . 今天 LZ 在运行一个程序的时候,出现找不到 so 库的情况: >$ ./core ./core: error : cannot open shared object fil ...

  6. TOMCAT的安装部署配置(配图解)

    TOMCAT的安装部署配置 前提已经成功搭建配置JDK 下载好压缩包后,直接解压至某一目录下,目录中不能包含中文 双击安装文件,出现如下界面 点击[NEXT],出现如下界面 点击[I AGREE],出 ...

  7. ajaxSubmit

    $('button').on('click', function() {    $('form').on('submit', function() {        var title = $('in ...

  8. WIN32_LEAN_AND_MEAN宏

    网上说: 不加载MFC所需的模块. 用英语解释:Say no to MFC 如果你的工程不使用MFC,就加上这句,这样一来在编译链接时,包括最后生成的一些供调试用的模块时,速度更快,容量更小. 我们经 ...

  9. android数据存储之外部存储(External Storage)

    Android设备支持外部存储器,可以是可移动存储器(如SD卡),也可以是内置在设备中的外部存储器(不可移动). 如果希望外部存储器上的文件只对本程序有用,并且当程序被卸载时目录中的文件自动被系统删除 ...

  10. brew 任何命令 都 报 synatx error

    brew 忽然不能用了,任何命令都报 syntax error near unexpected token `<<<' 解决方案 cd $(brew --prefix) git fe ...