http://codeforces.com/contest/738/problem/D

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 100100

output
24 2

input
13 3 2 31000000010001

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

题意:海战棋游戏,长度为n的01串,1代表炸过且没有船的位置,0代表没有炸过的位置。有a个船,长度都是b,求打到一艘船至少还需要多少炸弹,并输出炸的位置。

分析:每连续的b个0就要炸一次,不然不知道有没有是不是刚好一艘船在这b个位置上面。贪心可知炸这b个的最后一个最划算。因为只要炸到一艘即可,所以答案减去a-1,即有a-1艘可以不管它。

代码:

#include<cstdio>
#define N 200005
int a,b,n,k,d,ans,p[N];
char s[N];
int main(){scanf("%d%d%d%d%s",&n,&a,&b,&k,s);for(int i=0;s[i];i++){if(s[i]=='0')d++;if(s[i]=='1')d=0;if(d==b){d=0;ans++;p[ans]=i+1;}}ans-=a-1;printf("%d\n",ans);for(int i=1;i<=ans;i++)printf("%d ",p[i]);return 0;
}

  

【Codeforces 738D】Sea Battle(贪心)相关推荐

  1. codeforces:D. Sea Battle【跳跃性思维 + 贪心 + 逆向思维】

    分析 我们如果想击中全部的船 是不是全部连续的0段隔b个发一炮就可以(贪心) 现在我们想至少打中一个船 那就需要全部打中少a - 1次 这样就至少打中一个了 (如果都没打中的话,不可能a - 1次后打 ...

  2. 【Codeforces】158B-Taxi(贪心,怎么贪咧)

         贪心   emmmm http://codeforces.com/contest/158/problem/B 题目大意:有四种旅客,四人一组,三人一组,两人一组,一人一组,一辆出租车最多可以 ...

  3. CodeForces - 1607D Blue-Red Permutation(贪心)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列,每个数字有一个颜色,如果是蓝色,每次操作则可以减一:如果是红色,每次操作则可以加一. 问有限次操作后,能否将数组变为一个长度为 nnn 的 ...

  4. CodeForces - 1481E Sorting Books(贪心+dp)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,每次操作可以将任意一本书放到序列的末尾,问最少需要操作多少次,才能使得相同的数字挨在一起 题目分析:不难看出,对每个位置的数都操作一次,是 ...

  5. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  6. codeforces 735C Tennis Championship(贪心+递推)

    Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C --每天在线,欢迎留言谈论. 题目大意: 给你一个 n ...

  7. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  8. codeforces 1203 E Boxers 贪心

    https://codeforces.com/problemset/problem/1203/E 题目大意:给 n n n个数,每个数可以做两种变化:(1) + 1 +1 +1:(2) − 1 -1 ...

  9. Codeforces 854 C Planning 贪心 最大堆

    题目链接: https://vjudge.net/problem/CodeForces-854C 题目描述: 有n架飞机,第i架飞机原本计划在第i分钟起飞,可是由于某种原因整个机场前k分钟是不能起飞的 ...

最新文章

  1. 众人皆醉我独醒——深入理解“特征值”和“特征向量”
  2. C++之queue模板类
  3. ie不再询问加载java_fireFox IE刷新不提示
  4. mysql limit优化_MySQL:教你学会如何做性能分析与查询优化
  5. Spring AOP切面的时候参数的传递
  6. Class Activation Mapping(CAM)
  7. 只腐蚀毛刺 腐蚀算法_图像的腐蚀 膨胀及细化
  8. 小米商城项目解析(完)
  9. mysql强制编码导出、导入数据
  10. Mac项目流程管理工具:OmniPlan Pro 4.4
  11. ospf 几种LSA类型的总结
  12. 老妈~老妈~我爱你~~~~~~~阿弥陀佛保佑你~~~~~~~
  13. php 单位食堂订餐,职工食堂微信订餐系统 单位饭卡消费系统
  14. mysql数据库导入语句_mysql导入命令 mysql导入数据库语句
  15. python 列表比较不同物质的吸热能力_文章
  16. 沉思录之面向对象随想
  17. 十五、方差分析--使用Python进行单因素方差分析(ANOVA)
  18. 这一周我学习了什么(一)
  19. UVALive 3959 Rectangular Polygons (排序贪心)
  20. 【WIN10】win10更改以太网名称以及以太网下网络名称

热门文章

  1. Linux下HOOK动态链接库中API的方法
  2. Windows客户端C/C++编程规范“建议”——函数调用
  3. 打开,保存文件框的文本溢出排查
  4. WMI技术介绍和应用——查询桌面信息
  5. 【H2645】帧内预测
  6. 【MySQL】缩略语PK NN UQ BIN UN ZF AI G、基本操作语句
  7. linux内核 cpu_die,解密“内核”,和“cpu”又有啥关系?
  8. qcustomplot 游标吸附_qcustomplot游标测量功能--Apple的学习笔记
  9. Docker初学2:Docker的安装
  10. Java项目:控制台商城系统(java+打印控制台)