Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

时间:2022-12-23 23:30:38

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.

**题意:**给你一串长为n的格子,往里面放了a条长度为b的船,问最少打几个格子能打到一只船,输出数量和打的位置
**思路:**其实k根本没有什么用,考虑每个1和1之间的区间长度,计算最多能放几条船,这样相当于把船的长度离散化成1,比如样例二中总计能放4条船,而其中只放了3条船,打一发可能打到空格上,那么打两发就能保证一定能打到船。(cnt-a+1)

/** @Date    : 2016-11-20-21.32
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include<bits/stdc++.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+2000; char a[2*N];
int mr[2*N];
int main()
{
int n, m, l, k;
while(cin >> n >> m >> l >> k)
{
scanf("%s", a + 1);
int t = 0;
int cnt = 0;
int q = 0;
for(int i = 1; i <= n; i++)
{
if(a[i]=='1')
{
t = 0;
}
else t++;
if(t % l == 0 && t != 0)
{
cnt++;
mr[q++] = i;
}
}
int ans = cnt - m + 1;
cout << ans << endl;
for(int i = 0; i < ans; i++)
{
printf("%d%s", mr[i],i==ans-1?"\n":" ");
} }
return 0;
}

Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题的更多相关文章

  1. Codeforces Round &num;541 &lpar;Div&period; 2&rpar; A&period;Sea Battle

    链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...

  2. Codeforces Round &num;353 &lpar;Div&period; 2&rpar; C&period; Money Transfers &lpar;思维题&rpar;

    题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...

  3. 构造 Codeforces Round &num;302 &lpar;Div&period; 2&rpar; B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  4. Codeforces Round &num;367 &lpar;Div&period; 2&rpar; A&period; Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  5. Codeforces Round &num;575 &lpar;Div&period; 3&rpar; 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

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

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

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

  9. Codeforces Round &num;334 &lpar;Div&period; 2&rpar; A&period; Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

随机推荐

  1. Projects&bsol;Portal&lowbar;Content&bsol;Indexer&bsol;CiFiles文件夹下文件占用磁盘空间过大问题。

    C:\Program Files\Microsoft Office Servers\12.0\Data\Office Server\Applications\9765757d-15ee-432c-94 ...

  2. Flash Media Server 4&period;0 破解 注册

    Adobe Flash Media Interactive Server 3.5s/n:1373-5047-2985-0514-5175-0098 s/n: 1373-5632-4666-9521-8 ...

  3. Android—SQLITE数据库的设计和升降级

    Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLite 只需要带一个动 ...

  4. 【Java 基础篇】【第八课】package包

    学习Java以来,第一次感觉稍微有点不好理解的,下面说说吧. 存在意义: 包的存在就是为更好的组织结构 包的创建: 只要在程序的最前面加入 Package ******,就可以了,一般都喜欢写 com ...

  5. LTE切换与TAU问题

    假如有两个LTE基站A B(同频组网) AB TAC不同 且添加了双向邻区关系 现终端开机重选至A然后往B方向移动 是先切换呢?还是先进性TAU更新 这个没有影响,,TAU并非需要在IDLE状态下才能 ...

  6. *创造属于你的H5内容

    在这里,你可以*创造属于你的H5内容  mark下 http://www.ih5.cn/

  7. 解决Xcode6&period;4安装插件后插件不能使用的问题

    下面是上网查的方法,综合了一下,亲测 原因: 苹果要求加入UUID证书从而保证插件的稳定性. 解决方法: 一.查看Xcode的UUID 在终端执行 defaults read /Application ...

  8. IOS 特定于设备的开发&colon;检查设备接近度和电池状态

    UIDevice类提供了一些API,使你能够跟踪设备的特征,包括电池的状态和接近度传感器.他们二者都以通知的形式提供更新,可以订阅他们,以便在有重要的更新时通知你的应用程序. 1>启动和禁用接近 ...

  9. BZOJ 1207&colon; &lbrack;HNOI2004&rsqb;打鼹鼠&lpar; dp &rpar;

    dp.. dp[ i ] = max( dp[ j ] + 1 ) ------------------------------------------------------------------ ...

  10. java项目log4j日志打印配置

    #定义输出级别和输出平台  添加DEBUG表示打印sql 语句 log4j.rootLogger=DEBUG,INFO,ERROR,stdout,R log4j.category.org.spring ...