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. [Docker] docker 基础学习笔记5(共6篇)

    docker 配置文件的位置: centos : /etc/sysconfig/docker ubuntu: /etc/default/docker   现在比如我自己电脑上已经装好了docker,但 ...

  2. limux curl命令

    linux curl命令很强大: http://blog.chinaunix.net/uid-14735472-id-3413867.html curl是一种命令行工具,作用是发出网络请求,然后得到和 ...

  3. openssl和Java的keytool证书相关的命令总结

    Java的keytool keytool -genkey -alias myserver -keyalg RSA -keysize -keystore oauth-server.keystore -v ...

  4. lua和整合实践

    这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...

  5. java程序故障排查脚本之——CPU占用高

    root@ubuntu-B85M-D3H:~/tmp# cat java_Analy.sh #!/bin/bash T=`ps -mp $1 -o THREAD,tid,time|sort -k 2 ...

  6. C# Winform学习--- 实现石头剪刀布的游戏

    本文使用winform实现简单的石头剪刀布的游戏,主要实现,电脑随机出拳,玩家手动点击出拳:实现简易背景图片3秒切换:简易统计信息. 1.效果图 2.实现代码 新建一个windows窗体程序,用数字1 ...

  7. Android学习---ListView和Inflater的使用,将一个布局文件转化为一个对象

    本文将介绍ListView和Inflater的使用,将接上一篇文章内容. 一.什么是ListView? 在android开发中ListView是比较常用的控件,ListView 控件可使用四种不同视图 ...

  8. iOS修改button的点击范围

    一般来说,按钮的点击范围是跟按钮的大小一样的.若按钮很小时,想增大点击区域,网上通用的方法有①设置btn图片setImage,然后将btn的size设置的比图片大②在btn上添加一个比较大的透明btn ...

  9. 这有一个flag

    1.并查集[1224] 2.最小生成树?? 3.topsort(好洋气): 4.归并排序[1438]: 5.差分约束系统: 6.A*算法找k短路 7.scanf: 8.搜索[P1198]华容道: 9. ...

  10. 【python】将一个正整数分解质因数

    def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...