D. Sea Battle
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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

题意:给你一个01串长度为n,和a个长度为b的船;0位置可以放船,k个位置是1,求删掉最小位置的个数,使得放不下a条长度为b的船;

思路:找到01串(长度大于b)的开始第b个删掉,再将剩下的继续进行操作,直到满足条件为止;ps:比赛时代码写的搓不想改了;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e6+,M=1e6+,inf=1e9+;
const ll INF=1e18+,mod=;
char str[N];
queue<pair<int,int> >q;
vector<int>v;
int main()
{
int n,a,k,b;
scanf("%d%d%d%d",&n,&a,&b,&k);
scanf("%s",str+);
int pre=;
int ans=,f=;
for(int i=;i<=n;i++)
{
if(str[i]=='')
{
if(i-pre>=b)
{
q.push(make_pair(pre,i-));
f+=(i-pre)/b;
}
pre=i+;
}
}
if(n+-pre>=b)
{
q.push(make_pair(pre,n));
f+=(n-pre+)/b;
}
while(f>=a)
{
ans++;
pair<int,int> p=q.front();
q.pop();
int mid=p.first+b-;
v.push_back(mid);
f-=(p.second-p.first+)/b;
if(mid--p.first+>=b)
{
q.push(make_pair(p.first,mid-));
f+=(mid-p.first)/b;
}
if(p.second-mid>=b)
{
q.push(make_pair(mid+,p.second));
f+=(p.second-mid)/b;
}
}
printf("%d\n",ans);
for(int i=;i<v.size();i++)
printf("%d ",v[i]);
return ;
}

Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟的更多相关文章

  1. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  2. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  3. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  8. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. zabbix用自带模板监控mysql

    本身zabbix-agent没有提供对mysql监控的key,所以需要自定义key来应用这个模板 默认的模板有以下三类 mysql.status[var] mysql.ping mysql.versi ...

  2. wghd的git代码仓库分支管理说明【转】

    英文原文:http://www.nvie.com/posts/a-successful-git-branching-model/ 原文作者:Vincent Driessen 本文经Linux大棚博主总 ...

  3. Swoole 遇上 PHP会是怎样的结果呢

    一直想写点Swoole的东西,毕竟它重新定义了php,却一直不知道怎么下手写 Swoole涉及的知识点非常多,互为表里,每次想写都发现根本理不出一个头绪 Swoole是一个php的扩展,它的核心目的就 ...

  4. PHP将多张小图拼接成一张大图

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...

  5. php开启openssl的方法

    windows下开启方法: 1: 首先检查php.ini中:extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘:’, 如果不存在这行,那么添加extensio ...

  6. 收藏本网站兼容火狐IE

    <script type="text/javascript"> function AddFavorite(sURL, sTitle) {try { window.ext ...

  7. MySQL查询表内重复记录

    查询及删除重复记录的方法(一)1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select p ...

  8. quick-cocos2d-x 接入支付宝(android)(转,待验证)

    quick-cocos2d-x 实现在lua里面完成android支付宝的接入 一.支付宝注册是很麻烦的一个过程,本文就不解释了,想了解的去官网看下注册流程.然后下载他们的sdk-WS_SECURE_ ...

  9. java环境log4j日志环境的配置。

    首先需要4个jar包.下载地址如下 http://pan.baidu.com/s/1i4k3fiH 期中包含如下包,放到工程的lib中即可.     除此之外还需要一个配置文件,分享链接如下. htt ...

  10. word中设置前几页为罗马数字,后几页设置为阿拉伯数字

    假如第1-5页摘要部分页脚要是罗马数字,第6页开始是正文部分是阿拉伯数字,起始页为1. WORD2003 1.将光标定位在第5页末尾处,在菜单栏中依次点击“插入——分隔符——(分节符类型)下一页”.按 ...