Codeforces #380(Div.2)D.Sea Battle【贪心】好题~

来源:互联网 发布:儿童中文配音软件 编辑:程序博客网 时间:2024/05/29 08:30

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 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·1051 ≤ a, b ≤ n0 ≤ 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 100100
output
24 2
input
13 3 2 31000000010001
output
27 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的1*N的一个范围内,一共有a艘船,每只船长度为b,其中有K个已经轰炸过的位子,保证这些轰炸过的位子一定不是船的某部分,问你最少再轰炸多少次,就能轰炸到一个船的某部分,输出任意方案即可。

输入一行长度为N的字符串,其中1表示轰炸过的地方,0表示没有轰炸过的地方。


思路:


1、首先可以确定这样一个问题,如果有连续的b个0,那么这里很有可能就是一艘船,那么对应我们统计一共有多少个这样的位子。


2、假设我们现在用有cont个这样的位子,那么对应就有cont个地方可能有船,然而本身一共有a只船,而且题目要求只要轰炸都一只船的某一部分就可以了,那么对应我们只要轰炸cont-(a-1)次,就一定能够轰炸到某一只船的某一个部分,那么对应输出cont-(a-1)个任意可能有船的位子即可。


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;int ans[250000];char a[250000];int main(){    int n,b,aa,k;    while(~scanf("%d%d%d%d",&n,&aa,&b,&k))    {        scanf("%s",a);        int cnt=0;        int cont=0;        for(int i=0;i<n;i++)        {            if(a[i]=='0')            {                cnt++;                if(cnt==b)                {                    ans[cont++]=i;                    cnt=0;                }            }            else if(a[i]=='1')            {                cnt=0;            }        }        cont-=aa-1;        printf("%d\n",cont);        for(int i=0;i<cont;i++)        {            printf("%d ",ans[i]+1);        }        printf("\n");    }}





0 0
原创粉丝点击