• Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017


    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+10,M=1e6+10,inf=1e9+10;
    const ll INF=1e18+10,mod=2147493647;
    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+1);
        int pre=1;
        int ans=0,f=0;
        for(int i=1;i<=n;i++)
        {
            if(str[i]=='1')
            {
                if(i-pre>=b)
                {
                    q.push(make_pair(pre,i-1));
                    f+=(i-pre)/b;
                }
                pre=i+1;
            }
        }
        if(n+1-pre>=b)
        {
            q.push(make_pair(pre,n));
            f+=(n-pre+1)/b;
        }
        while(f>=a)
        {
            ans++;
            pair<int,int> p=q.front();
            q.pop();
            int mid=p.first+b-1;
            v.push_back(mid);
            f-=(p.second-p.first+1)/b;
            if(mid-1-p.first+1>=b)
            {
                q.push(make_pair(p.first,mid-1));
                f+=(mid-p.first)/b;
            }
            if(p.second-mid>=b)
            {
                q.push(make_pair(mid+1,p.second));
                f+=(p.second-mid)/b;
            }
        }
        printf("%d
    ",ans);
        for(int i=0;i<v.size();i++)
            printf("%d ",v[i]);
        return 0;
    }
  • 相关阅读:
    Java异常
    Vector ArrayList LinkedList
    线程池
    Linux alias 或者 unalias 设置别名
    vim 知识点小结
    vim下出现^M怎么解决
    解决pip安装时出现报错TypeError unsupported operand type(s) for -= 'Retry' and 'int'
    MySQL备份与恢复
    mysql 去重的两种方式
    查看python的安装版本,位数及安装路径
  • 原文地址:https://www.cnblogs.com/jhz033/p/6090937.html
Copyright © 2020-2023  润新知