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
  1. 5 1 2 1
    00100
output
  1. 2
    4 2
input
  1. 13 3 2 3
    1000000010001
output
  1. 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个就开始标记;

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cstring>
  8. #include <string>
  9. #include <set>
  10. #include <map>
  11. #include <unordered_map>
  12. #include <queue>
  13. #include <stack>
  14. #include <vector>
  15. #include <list>
  16. #define rep(i,m,n) for(i=m;i<=n;i++)
  17. #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
  18. #define mod 1000000007
  19. #define inf 0x3f3f3f3f
  20. #define vi vector<int>
  21. #define pb push_back
  22. #define mp make_pair
  23. #define fi first
  24. #define se second
  25. #define ll long long
  26. #define pi acos(-1.0)
  27. #define pii pair<int,int>
  28. #define Lson L, mid, ls[rt]
  29. #define Rson mid+1, R, rs[rt]
  30. #define sys system("pause")
  31. #define intxt freopen("in.txt","r",stdin)
  32. const int maxn=2e5+;
  33. using namespace std;
  34. ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
  35. ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
  36. inline ll read()
  37. {
  38. ll x=;int f=;char ch=getchar();
  39. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  40. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  41. return x*f;
  42. }
  43. int n,m,k,t,cnt,num,a,b;
  44. char s[maxn];
  45. vi ans;
  46. int main()
  47. {
  48. int i,j;
  49. scanf("%d%d%d%d%s",&n,&a,&b,&k,s);
  50. for(i=;s[i];i++)
  51. {
  52. if(s[i]==''){
  53. cnt++;
  54. if(cnt==b){
  55. num++,cnt=;
  56. if(num>=a)ans.pb(i+);
  57. }
  58. }
  59. else cnt=;
  60. }
  61. printf("%d\n",(int)ans.size());
  62. for(int x:ans)printf("%d ",x);
  63. //system("Pause");
  64. return ;
  65. }

Sea Battle的更多相关文章

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

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

  2. Codeforces 738D. Sea Battle 模拟

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

  3. Codeforces #380 div2 D(729D) Sea Battle

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

  4. 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 ...

  5. 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 ...

  6. Sea Battle<海战>(思路题)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 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 ...

  8. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. A. Sea Battle

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

随机推荐

  1. 常见编程语言对REPL支持情况小结[转]

    文章转载自http://www.nowamagic.net/librarys/veda/detail/2462 最近跟一个朋友聊起编程语言的一些特性,他有个言论让我略有所思:“不能REPL的都是渣”. ...

  2. geom设置—条形图

    条形图可能是所有图形里面最基本的图形了,虽然很简单,在R里面有些地方不注意,还是会很容易出错. geom_bar()的基本参数情况 geom_bar(mapping = NULL, data = NU ...

  3. 4、Web应用程序中的安全向量 -- over-posting(重复提交)

    模型绑定是ASP.NET MVC提供的强大功能,可遵照命名约定将输入元素映射到模型属性,从而极大地简化了处理用户输入的过程,然而,这也成为了攻击的另一种没接,给攻击者提供了一个填充模型属性的机会,右下 ...

  4. 信息处理,分而治之-- ESFramework 使用技巧

     ESFramework开发手册系列文章已经详细介绍了如何使用ESPlus提供的ESPlus.Application.CustomizeInfo空间来发送和处理自定义信息,而且,在我们在前面介绍的de ...

  5. markdown 自己搞一个浏览工具

    注意!`下不能有空行 `上也不能有空行 问题未解决 <!DOCTYPE html> <html lang="en"> <head> <me ...

  6. HTML转PDF

    1)使用工具转换.如:wkhtmltopdf 2)Chrome浏览器打印功能中,有另存为PDF格式文件.(推荐最便捷)

  7. C#第七天

    一 1.继承:我们可能会在一些类中,写一些重要的成员,将这些重复的成员单独的封装到一个类中,作为这些类的父类. Student    Teacher     Driver               ...

  8. linux下写脚本时-gt是什么意思

    -eq 等于-ne 不等于-gt 大于-ge 大于等于-lt 小于-le 小于等于

  9. finally语句包含return的情况

    结论:1.不管有木有出现异常,finally块中代码都会执行:2.当try和catch中有return时,finally仍然会执行:3.finally是在return后面的表达式运算后执行的(此时并没 ...

  10. wireshark 包过滤

    tcp.port == 443 or udp.port==443 or tcp.port==53 or udp.port==53