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

    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?"
    ":" ");
            }
    
        }
        return 0;
    }
    
    
  • 相关阅读:
    openfire部署文档(备用)
    WPS目录制作方法
    Spring.net Could not load type from string value问题解决办法
    [转载]线程间操作无效: 从不是创建控件“ListBox1”的线程访问它
    [转载].Net中如何操作IIS(源代码)
    [转载]DirectoryEntry配置IIS7出现ADSI Error:未知错误(0x80005000)
    [转载]Sublime Text 2
    [转载]再谈iframe自适应高度
    js key事件 keyCode大全
    [转载]HTML5 Audio/Video 标签,属性,方法,事件汇总
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6083668.html
Copyright © 2011-2022 走看看