Codeforces Round #Pi (Div. 2)-D. One-Dimensional Battle Ships (set + 2 minutes)

The meaning of the question: Given a 1*n grid, there are k 1*a ships, and the ships cannot overlap or touch. There are m queries, and each query gives a position i, which represents the ith in the cutting game. Ask the first question to start, the grid has been unable to put down k ships

Idea: The number of times the bisection can be cut

        set + two points, each time you ask, insert the current position, and update it with the two adjacent positions to see if there are fewer ships that can be placed  

/*
Two points/set
Idea: 2 points/set + 2 points, each time you ask, whether the number of ships that can be updated has decreased
*/
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5+5;
set<int> s;
int n,m,k,a,b,ans;

int main(){
    cin>>n>>k>>a;
    s.clear();
    cin>>m;
    int flag=0;
    s.insert(0);
    s.insert(n+1);
    ans=(n+1)/(a+1);
    for (int i=1; i<=m; i++){
        cin>>b;
        if (flag==0){
            int c=*s.lower_bound(b);
            int d=*--s.lower_bound(b);
            s.insert(b);
            ans-=(cd)/(a+1);
            ans+=(c-b)/(a+1)+(b-d)/(a+1);
            if (ans<k) flag=i;
        }
    }   
    if (flag) cout<<flag<<endl;
    else cout<<-1<<endl;

    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324694664&siteId=291194637