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. error C4996: 'fopen': This function or variable may be unsafe.

    vs2013中错误提示信息: error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s ...

  2. oracle常用命令大全及心得

    学习时整理的 Oracle 1.set linesize 100; 设置长度2.set pagesize 30; 设置每页显示数目3.em a.sql 打开记事本 4.@ a 执行文件a中的代码,可指 ...

  3. MD5实现32位加密

    好记性不如烂笔头,随手记记 附代码 public static void Main(string[] args) { Console.WriteLine("长度为" + UseMd ...

  4. 微信公众账号第三方平台全网发布源码(java)- 实战测试通过

    第一部分:微信第三方平台配置

  5. 自适应UITableView的Cell高度问题

    1.自己计算Cell的高度返回: 1>model中计算: // // InfoModel.h // OCDemo // // Created by 思 彭 on 16/12/27. // Cop ...

  6. div赋值,取值和input赋值,取值

    一.div取值 <div id="txtXiaofei" class="txt-panel">你好</div> 获取div的值$(&qu ...

  7. flash中网页跳转总结

    浏览器中,程序同时跳转两个网页地址,第一个地址不会跳转,只会跳转第二个地址,如果第二个地址做延时,则第一个正常跳转,第二个地址会被拦截: 浏览器中,接口返回事件的函数中不能程序跳转网页地址. 这两条结 ...

  8. MySQL-Front 建表引发的一点小思考(数据表格模版)

    我们建表的时候,有一些字段总是会常用到的.也就是每一张表都会有这些字段. 我用mysql有一点时间了,今天(2016-02-27 21:53:38)在用mysql-front建表的时候,感觉有点点不太 ...

  9. 我的Git使用-资料查询,名博笔记

    1.首先您要知道什么是GIT 2.然后对其GIT的历史有所了解(吹牛b的时候用得着,如果还不知道 linux 脱袜子 Linus Torvalds  o(︶︿︶)o ) Git 常用资料查询站点. 官 ...

  10. 压缩文本、字节或者文件的压缩辅助类-GZipHelper

    下面为大家介绍一.NET下辅助公共类GZipHelper,该工具类主要作用是对文本.字符.文件等进行压缩与解压.该类主要使用命名空间:System.IO.Compression下的GZipStream ...