time limit per test1 second
            memory limit per test256 megabytes
              inputstandard input
              outputstandard 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 b consecutive 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 n, a, b, k (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.

#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;const int INF=1e9+7;
const int maxn=201000;
int main()
{int map[maxn],p[maxn];int n,a,b,k,sum=0,ans=0;scanf("%d%d%d%d",&n,&a,&b,&k);for(int i=1; i<=n; i++)scanf("%1d",&map[i]);for(int i=1; i<=n; i++){if(map[i]==0){sum++;//假设b个点就有一条船if(sum==b){sum-=b;p[++ans]=i;//printf("p[ans]=%d \n",p[ans]);}}else //为1,则一定没有船,从0开始计数sum=0;}//一共a条船,由于只需要打掉一条船,那么只需将可能有船的点打到只剩 (a-1) 就行了 (**ans是每b个数记一次**)printf("%d\n",ans-(a-1));for(int i=1; i<=ans-a+1; i++)printf("%d ",p[i]);return 0;
}

转载于:https://www.cnblogs.com/nyist-xsk/p/7264856.html

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. AtCoder Grand Contest 004 C - AND Grid(思路题)

    题意: 给你一个n*m的矩阵,矩阵中有.和#,#表示两图重合的部分,边缘没有# 然后要你构造两个n*m的图,要求#是连通的,然后合并之后重合的部分就是原图中的# 思路: 又是一到思路题 当时被B题智商 ...

  3. UVA 12898 - And Or 与和或 (思路题)

    思路就是有零一变化的位Or以后一定是1,And以后一定是0:那么如果b的二进制更长那么就把包含a的部分全部置为1或0,如果一样长那么就把不同的部分置为1或0. 今天被这题坑的地方:1默认是int,如果 ...

  4. Sea Battle

    https://codeforces.com/contest/1131/problem/A 题解:简单题 把周长加起来就完事了 /* *@Author: STZG *@Language: C++ */ ...

  5. P3514-[POI2011]LIZ-Lollipop【思路题】

    正题 题目链接:https://www.luogu.org/problemnew/show/P3514 题目大意 一个12序列,若干个询问求有没有一个子串之和为kkk 解题思路 首先感谢ZYCdala ...

  6. 【LeetCode笔记】221. 最大正方形(Java、动态规划、思路题)

    文章目录 题目描述 思路 & 代码 更新版 题目描述 显而易见地可以用dp来写,问题在于如何考虑状态转移方程 思路 & 代码 首先再加一层外墙,就不用边界判断了 maxSqure[i] ...

  7. 【LeetCode笔记】238. 除自身以外数组的乘积(Java、思路题)

    文章目录 题目描述 思路 & 代码 更新版 题目描述 首先暴力二层循环肯定可以,然后先累乘整个数组,再用除法肯定也行. 但是很遗憾,两种做法都不满足题目说明. 思路 & 代码 O(n) ...

  8. 【思路题】【多校第一场】【1001.OO’s Sequence】

    题目大意: 给你一个序列A,f(l,r) 表示 在[l,r]中 的Ai 对于每一个数Aj 都有 Ai%Aj!=0  的数目(  i!=j  ) 卡了一段时间..... 题解 简单题 定义两个数组L[i ...

  9. agc012E Camel and Oases(状压dp+思路题)

    这题神啊.状压dp你敢信?思维难度爆表还有一堆细节要注意???orz Visjiao 原题链接:http://agc012.contest.atcoder.jp/tasks/agc012_e 大神题解 ...

  10. zoj 2316 Matrix Multiplication 【思路题】

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2316: 题目大意:给 n*n的矩阵 A,求 A∗AT所有元素和( ...

最新文章

  1. 海淀温泉镇迎来大爆发!5G基站、产业转移示范基地、自动驾驶核心测试区.........
  2. 在CentOS6.x下安装Compiz——桌面立方体,特效种种
  3. c库函数tmpfile
  4. 浏览器指纹实现方案:Cookie、Flash Cookies、帆布指纹识别
  5. 免费计算机维修基础教程,《计算机组装与维修基础教程》第1课:计算机基础知识.ppt...
  6. 嵌入式开发概述(树莓派介绍)
  7. [转载] Java面试题大全(2020版)
  8. 444 nginx_程序员安全规范:安全无小事,安全防范从nginx配置做起
  9. 打通应用隔阂,AR 如何助力互联网度过寒冬?
  10. 2019/3/14 软工作业
  11. JS Cookies
  12. 分布排序(distribution sorts)算法大串讲
  13. Using Java in Debian
  14. matlab程序转成可执行文件,matlab程序如何生成可执行文件
  15. 二维码扫码登陆流程设计
  16. 笔记本进入pe却看不到计算机硬盘,一些笔记本进WINPE后找不到硬盘的解决办法...
  17. 多元统计分析及R语言建模(王斌会)第五、六、七章答案
  18. 专访全面智能CTO陈章:想法只有在技术落地的那一刻才有撬动地球的能力
  19. 带你区分超键,候选键,主键
  20. 让 P-value 更加的浅显易懂

热门文章

  1. Redis源码阅读 (备份机制)
  2. 前台传递过来的参数遍历
  3. java判断端口是否可用
  4. java.util.stream.DoubleStream
  5. Jenkins任务配置详解,支持ssh远程部署,maven聚合项目,springboot
  6. .net mysql参数化查询,ASP.NET中的mysql参数化查询
  7. java递推_【Java】递归递推的应用
  8. Python进阶(八)Python中的关键字
  9. 推荐系统笔记二、矩阵分解协同过滤
  10. 推荐系统 | 信息过载的大数据时代,大数据推荐系统如何搭建,趋势何方