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. 【简易版】HashMap(增删改查)

    1.HashMap概述 (1)首先HashMap是基于哈希表的Map接口实现的.另外HashMap中存储的数据是按照键值跟键值对的关系来进行存储的. (2)不同于ArrayList方法的是,Array ...

  2. 纯js异步无刷新请求(只支持IE)

    纯js异步无刷新请求 下载地址:http://pan.baidu.com/s/1slakL1F 所以因为非IE浏览器都禁止跨域请求,所以以只支持IE. <HTML> <!-- 乱码( ...

  3. 完整地mybatis + springmvc用checkbox实现批量删除

    因为自己在网上找了半天,都找不到完整地代码(脑袋笨,不会变通到自己项目里),所以在这里记下了近乎完整的代码 前端代码 <span style="cursor:pointer;" ...

  4. Xcode - 知道.001

    1.在xcode7以后,一定要有根视图,否则会报错,程序崩溃,

  5. Oracle数据访问组件ODAC的安装方法:

    Oracle数据访问组件ODAC(Oracle Data Access Components)顾名思义就是用来访问Oracle数据库的小程序.我们可以编程调用这些组件来实现在没有安装Oracle数据库 ...

  6. H5表单中placeholder属性的字体颜色问题

    最近做项目的时候遇到的一些小样式问题,有关表单.并且在接下来几天的面试人中五个人都没有回答上来,改变placeholder属性的默认字体颜色,感觉有必要总结一下. 如何改变默认字体的颜色? @blue ...

  7. VScode常用几个前端插件live HTML previewer和debugger for chrome的配置

    之前一直都是用sublime Text和chrome配合来写前端的页面,自从知道了有liveReload这个神奇的插件之后感觉爽翻了啊.好吧跑远了........ 话说最近微软搞了个VScode,听说 ...

  8. java中的static使用--静态变量、静态方法

    Java 中的 static 使用之静态变量 大家都知道,我们可以基于一个类创建多个该类的对象,每个对象都拥有自己的成员,互相独立.然而在某些时候,我们更希望该类所有的对象共享同一个成员.此时就是 s ...

  9. Mina传输大数组,多路解码,粘包问题的处理

    我的实际情况: 1,传递的业务数据种类很多,这就决定了我们要用多路解码器,MINA的中文手册提供的是DemuxingProtocolCodecFactory; 2,,有的数据长度达到8K,网上有资料说 ...

  10. solr安装笔记与定时器任务

    一:solr启动 目前solr最高版本为5.5.0版本,很多solr安装都是说将server文件copy到tomcat中,但是solr版本自带有jetty的启动方式 首先下载solr-5.5.0版本, ...