【Codeforces 738D】Sea Battle(贪心)

时间:2022-01-02 23:24:25

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

题意:海战棋游戏,长度为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=;s[i];i++){
if(s[i]=='')d++;
if(s[i]=='')d=;
if(d==b){
d=;
ans++;
p[ans]=i+;
}
}
ans-=a-;
printf("%d\n",ans); for(int i=;i<=ans;i++)
printf("%d ",p[i]);
return ;
}

  

【Codeforces 738D】Sea Battle(贪心)的更多相关文章

  1. Codeforces 738D&period; Sea Battle 模拟

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

  2. CodeForces 738D Sea Battle

    抽屉原理. 先统计最多有$sum$个船可以放,假设打了$sum-a$枪都没打中$a$个船中的任意一个,那么再打$1$枪必中. #pragma comment(linker, "/STACK: ...

  3. Codeforces 729D Sea Battle&lpar;简单思维题&rpar;

    http://codeforces.com/contest/738/problem/D https://www.cnblogs.com/flipped/p/6086615.html   原 题意:海战 ...

  4. Codeforces Round &num;380 &lpar;Div&period; 2)D&period; Sea Battle

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

  5. 【42&period;86&percnt;】【Codeforces Round &num;380D】Sea Battle

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

  6. Codeforces &num;380 div2 D&lpar;729D&rpar; Sea Battle

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

  7. Codeforces Round &num;380 &lpar;Div&period; 2&comma; Rated&comma; Based on Technocup 2017 - Elimination Round 2&rpar; D&period; Sea Battle 模拟

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

  8. Codeforces Round &num;380 &lpar;Div&period; 2&rpar;&sol;729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  9. Sea Battle

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

随机推荐

  1. 【初学者教程】在电脑上安装Python,写第一个程序

    欢迎来到Python的世界 1.存在Python 2和Python 3两个版本,我该用哪个?如果书是关于2的,下载2:如果书是关于3的,就下载3.建议用Python 3,不过用2也是可以的. 2.下载 ...

  2. Routed Events【pluralsight】

    Routing Strategies: Direct Bubbling Tunneling WHy use them? Any UIElement can be a listener Common h ...

  3. bazel 测试过程

    google的bazel如日中天,尽管我觉得make已经很好用,但是还是尝试一下,记录之. 首先,从 https://github.com/bazelbuild/bazel/releases 下载对应 ...

  4. 模式识别笔记3-支持向量机SVM

    1. 线性SVM 对两类点的划分问题,这里对比下逻辑回归和SVM的区别: 逻辑回归的思想是,将所有点到决策平面的距离作为损失来进行训练,目标是到决策平面的距离和最小 SVM的思想是,只关注支持向量(图 ...

  5. Linux下基础查看命令

    1:查看系统32位还是64位,如下三种方法       uname -m        uname -a        ls -ld  /lib64 2:查看系统版本   cat /etc/redha ...

  6. centos7系统下,配置学校客户端网络记录

    存在的情况 1.学校的网络客户端绑定了个人的电脑MAC地址.绑定了IP地址. 2.我有两台笔记本,一台用了4年多,想用这台(B)直接装centos7系统,然后新买的笔记本(A)做为经常用的,系统为wi ...

  7. Java实现浏览器端大文件分片上传

    版权所有 2009-2018荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/up6.2/in ...

  8. 使用 CoreTelephony 框架获取当前网络运营商

    CoreTelephony 获取运营商信息,需通过 CoreTelephony.Framework 中的 CTTelephonyNetworkInfo 和 CTCarrier 对象获取,这些都在iOS ...

  9. BZOJ 2876 【NOI2012】 骑行川藏

    题目链接:骑行川藏 听说这道题需要一些高数知识 于是膜了一发dalao的题解……然后就没了…… 不要吐槽我的精度TAT……eps设太小了就TLE,大了就Wa……我二分的边界是对着数据卡的…… 下面贴代 ...

  10. 机器学习,数据挖掘,统计学,云计算,众包(crowdsourcing),人工智能,降维(Dimension reduction)

    机器学习 Machine Learning:提供数据分析的能力,机器学习是大数据时代必不可少的核心技术,道理很简单:收集.存储.传输.管理大数据的目的,是为了“利用”大数据,而如果没有机器学习技术分析 ...