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. 加载执行预编译的Sql :prepareStatement

    1.获得连接:Connection con = null; con = DBUtil.getConnection(); 2.写sql语句:String sql=""; 3.用连接加 ...

  2. 【python cookbook】【字符串与文本】15.给字符串中的变量名做插值处理

    问题:想创建一个字符串,其中嵌入的变量名称会以变量的字符串值形式替换掉 解决方法:str.format().str.format_map() >>> s = '{name} has ...

  3. 161102、MyBatis中批量插入

    方法一: <insert id="insertbatch" parameterType="java.util.List"> <selectKe ...

  4. ExtJS的MessageBox总结

    自己写了个ExtJS的MsgBox的小模版,以后遇到需要使用提示的地方就拿过来改改,免得每次都重新写. /**MsgBox start**/ Ext.Msg.buttonText.yes = &quo ...

  5. Hosting custom WPF calendar control in AX 2012

    原作者: https://community.dynamics.com/ax/b/axilicious/archive/2013/05/20/hosting-custom-wpf-calendar-c ...

  6. 关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法

    关于Quartus II 13.0对应开发NIOS II软件程序时报错Symbol 'NULL' could not be resolved问题的解决方法 近期在评估使用NIOS II处理器进行项目的 ...

  7. HDU 2444:The Accomodation of Students(二分图判定+匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:给出边,判断这个是否是一个二分图,并求最大匹配. 思路:先染色法求出是否是一个二分图,然后再匈牙利求 ...

  8. symfony中twig的流程控制if,for用法

    流程控制 if 语句 if语句在twig中的作用如同if语句在PHP中的一样.1.你可以通过下面这个简单的例子来判断表达式的结果是否正确. {% if online == false %} <p ...

  9. hdwiki中模板的使用说明

    HDwiki所有模版文件都在根目录view下的default文件里,以admin_开头的是后台的模版文件,其它不是以admin_开头的,就是所有的前台文件.具体列表如下:首页模版文件:  index. ...

  10. 默认调用电脑IE版本最高版本

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />