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 ...
随机推荐
- ViewState提交后丢失,竟然是OnInit搞的鬼
提交后报错,断点看ViewStat值没有了.排查半天完全不知道怎么回事. 百度搜索了下ViewState提交丢失.然后CSDN一个帖子说的半拉子话提点了我. 然后想到我经常重写这些函数.以前怎么没遇到 ...
- 重置zend studio 默认设置的方法
转载自:http://www.zendstudio.net/archives/reset-the-zend-studio-settings/ 这个方法类似于手机的"恢复出厂设置"的 ...
- 【转】sql server获取数据库名,表明,表结构
1.查询数据库中的所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.查询某个数据库中所有的表名: SELECT Name FR ...
- Build OpenCV text(OCR) module on windows
Background. AOI software needs to use the OCR feature to recognize the texts on the chips. Because o ...
- mysql source导入报错ERROR 1366的解决方法
文件是utf8的,数据库表是utf8的,为什么客户端导入会报错呢? 发现客户端用的是gbk的 改为utf8后正常 SHOW VARIABLES LIKE 'character%'; +-------- ...
- svn更新操作时提示database is locked
If you're on Windows version just let's do the next: Right click on the repo folder and go to Tortoi ...
- vim中 set 用法设置
vi set用法from google search一.常用收集如下:(vi set)set autoindent 在插入模式下,对每行按与上行同样的标准进行缩进,与shiftwidth选项结 ...
- win8.1 64位安装DEV C++
1.首先下载64位版本的DEV C++ http://sourceforge.net/projects/orwelldevcpp/files/Setup%20Releases/ 2.采取默认安装即可, ...
- windbg学习----.process
.process 命令指定要用作进程上下文的进程(Set Process Context) .process显示当前进程的EPROCESS,这里显示当前进程为test.exe kd> .proc ...
- AS3 转 Java
不错,我就是as3转java的程序猿. 大概两年前加过as3的QQ群里,有很多群友说as3发展前景不好,很多要转语言.我当时也想转,一直苦于没机会.现在机会终于来了... 首先说明一点,as3并不会像 ...