zoukankan      html  css  js  c++  java
  • Codeforces Round #380 (Div. 2)D. Sea Battle

    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.

    /*
    RE返回T我也是醉了.......
    */
    /*
    贪心先看海面上能撑下几艘船。然后只要打sum-a+1个点就能保证至少能达到一艘船
    */
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        //freopen("C:\Users\acer\Desktop\in.txt","r",stdin);
        int n,a,b,k;
        char op[200005];
        scanf("%d%d%d%d",&n,&a,&b,&k);
        scanf("%s",op+1);
        //cout<<op<<endl;
        vector<int>v;
        int l=0;
        for(int i=1;i<=n;i++){
            //cout<<op[i];
            if(op[i]=='1'){
                l=i;
            }
            if(i-l==b){
                v.push_back(i);
                l=i;
            }
        }
        //cout<<endl;
        printf("%d
    ",v.size()-a+1);
        for(int i=0;i<v.size()-a+1;i++)
            printf(i?" %d":"%d",v[i]);
        return 0;
    }
  • 相关阅读:
    日期计算
    普通二叉树转换成搜索二叉树
    每周行情
    virtualbox安装增强功能时【未能加载虚拟光盘】
    linux实用命令之如何移动文件夹及文件下所有文件
    Linux文件夹文件创建、删除
    php 克隆 clone
    function_exists (),method_exists()与is_callable()的区别
    webgrind安装使用详细说明
    windows下redis的安装配置和php扩展使用phpredis
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6085696.html
Copyright © 2011-2022 走看看