Codeforces 738D. Sea Battle 模拟
1 second
:256 megabytes
standard input
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.
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.
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.
5 1 2 1
00100
2
4 2
13 3 2 3
1000000010001
2
7 11
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串,现在有a艘长度为b的飞船停在0上面,飞船长度是连续的,并且一个0上面最多只能有1艘飞船。求最少打击多少个位置能够打击到一个飞船。
思路:模拟题。每b个连续的0就要打击一次。直至剩下的打击数量为a-1。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2e5+;
int ans[MAXN];
int main()
{
int n,a,b,k;
char ch;
scanf("%d%d%d%d",&n,&a,&b,&k);
getchar();
int sign=;
int i,j=;
for(i=; i<=n; i++)
{
scanf("%c",&ch);
if(ch=='')
{
sign++;
if(sign%b==) ans[j++]=i;
}
else sign=;
}
cout<<j-(a-)<<endl;
for(i=; i<j-(a-); i++) cout<<ans[i]<<" ";
cout<<endl;
return ;
}
Codeforces 738D. Sea Battle 模拟的更多相关文章
- CodeForces 738D Sea Battle
抽屉原理. 先统计最多有$sum$个船可以放,假设打了$sum-a$枪都没打中$a$个船中的任意一个,那么再打$1$枪必中. #pragma comment(linker, "/STACK: ...
- 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 ...
- Codeforces 729D Sea Battle(简单思维题)
http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html 原 题意:海战 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- 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 ...
- 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 ...
- Sea Battle
Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
随机推荐
- 1045 access denied for user 'root'@'localhost' using password yes的解决方法
今天把一个项目和项目的数据库都下载到了本地,安装好项目和在本地配置好数据库后,在浏览器登陆项目的后台却出现了以下错误: 后来上百度搜索了好几个答案,都是讲述修改数据库密码的步骤,但是就是没有说明为 ...
- html5 history api
1.html5 history api适用场景,个人理解最大的用处是配合ajax使用,使ajax拥有回退.前进的用户体验. 2.代码(dive into html5中的一个小例子) 1)fer.htm ...
- SpringMVC学习笔记(四)
一.Controller接受网页参数. 1.使用方法的形参来接受 //使用基本类型和字符串来接受 @RequestMapping(value="/param2.do") publi ...
- 00904. 00000 - "%s: invalid identifier"
SELECT * FROM table name WHERE STRING_VALUE like '%Britaney Searing%' ORDER BY COMPOSITE_INSTANCE_ID ...
- Hcm data loader for cancel work relationship
好好总结一下这个task.没有做好的东西:1.现有的资料和各种各样的工具没有很好的利用起来,造成了用了很多的时间去了解和自己学习.非常的不舒服的.下次要避免这样的浪费时间,学会在工作中学习.现在以及以 ...
- Office 365系列六 ------ 创建sharepoint online网站
这节跟大家介绍简单的创建sharep online私有网站集,sharepoint online 可以给我们提供开箱即用的功能,比如文档库:可以给我们取代File Server,提供了版本管理,版本变 ...
- Linux驱动学习之什么是驱动?
一.什么是驱动? 1: 驱动一词的字面意思 2: 物理上的驱动 3: 硬件中的驱动 4: linux内核驱动.软件层面上的驱动广义上是指:这一段代码操作了硬件去动,所以这一段代码就叫硬件的驱动程序. ...
- git ssh端口号变更之后所需要的修改
假设原本的repository地址为:git@gitlab.cjx.com:jinxin/project2.git 端口变更之后,需要调整为:ssh://git@gitlab.cjx.com:PORT ...
- 有关Select option 元素
动态添加option元素以及option元素被选中方法: function getType() { ); shadowCoverTipAdd("加载中,请稍候.."); $.aja ...
- Android菜鸟成长记14 -- AsnyTask
本篇随笔将讲解一下Android的多线程的知识,以及如何通过AsyncTask机制来实现线程之间的通信. 一.Android当中的多线程 在Android当中,当一个应用程序的组件启动的时候,并且没有 ...