Codeforces Round #380 Div. 1 B. Sea Battle(贪心)

185 篇文章 0 订阅
65 篇文章 0 订阅

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.


题意:现在有一个1*n的棋盘,有a艘长度为b的船分布在棋盘上,船不允许重叠但可以首尾相接,你不知道船的位置,每次可以选一个方格开枪,如果这个方格内有船体则返回击中,现在你已经开了K枪但是都没有命中,问你至少再开多少枪可以保证至少命中一次,要求输出每枪的位置。


分析:在开一枪后棋盘被分为两部分,假设原本长度为n,在l处开一枪,那么棋盘的容纳了就由n/b变成了(l-1)/b + (n-l)/b,可以看出(l-1)/b + (n-l)/b >= n/b - 1,那么每枪最多只能让棋盘的容纳量减一,我们让l = b就可以保证每次都能让棋盘容量减一,当棋盘容量减到a-1时停止。


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define N 200005  
using namespace std;
int n,A,b,k,s,t,tot,a[N];
vector<int> q;
int main()
{
	scanf("%d%d%d%d",&n,&A,&b,&k);
	char c;
	scanf("%c",&c);
	for(int i = 1;i <= n;i++) scanf("%c",&a[i]);
	int t = 0;
	for(int i = 1;i <= n;i++)
	{
		if(a[i] == '0') t++;
		else t = 0;
		tot += t/b;
		t %= b;
	}
	t = 0;
	for(int i = 1;i <= n && tot >= A;i++)
	{
		if(a[i] == '0') t++;
		else t = 0;
		if(t == b)
		{
			q.push_back(i);
			t = 0;
			tot--;
		}
	}
	cout<<q.size()<<endl;
	for(int i : q) cout<<i<<" ";
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值