CF D. One-Dimensional Battle Ships

一个set水 + 区间判断个数问题。。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
int L,N,a,M;
int main()
{
    set<int> Pos;
    set<int>::iterator it;
    cin >> L >> N >> a;
    {
        Pos.clear();
        Pos.insert(0),Pos.insert(L+1);
        int ans =1 + (L - a) / (a + 1);
        cin >> M;
        for(int i = 1; i <= M; ++i)
        {
            int x;
            cin >> x;
            it = Pos.lower_bound(x);
            int r = *it - 1;
            int l = *(--it) + 1;
            int len = r - l + 1;
            int Sum = 0, SumR = 0, SumL = 0;
            if(len >= a)
                Sum = 1 + (len - a) / (a + 1);
            if(x - l >= a)
                SumL = 1 + (x - l - a) / (a + 1);
            if(r - x >= a)
                SumR = 1 + (r - x - a) / (a + 1);
            ans = ans - Sum + SumL + SumR;
            if(ans < N) {
                cout << i << endl;
                return 0;
            }
            Pos.insert(x);
        }
        cout << "-1\n";
    }
    return 0;
 }
时间: 2024-08-03 11:27:34

CF D. One-Dimensional Battle Ships的相关文章

hdu 5093 Battle ships 最大二分匹配

Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 233 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible

ZOJ3623:Battle Ships(完全背包)

Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes tiseconds to produce the

Battle ships(二分图,建图,好题)

Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1007    Accepted Submission(s): 353 Problem Description Dear contestant, now you are an excellent navy commander, who is responsible

zoj3623 Battle Ships

Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes ti seconds to produce th

zoj 3623 Battle Ships dp

 Description Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes ti second

Battle Ships(复习泛化物品**)

传送门Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N

ZOJ3623 Battle Ships (完全背包)

Battle Ships Time Limit: 2 Seconds      Memory Limit: 65536 KB Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N ki

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

Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1?×?n table). At the beginning of the game Alice puts k ships on the field without telling their positio

Battle Ships(完全背包)

Battle ShipsCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defens

ZOJ3623:Battle Ships(全然背包)

Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity. The player has a military factory, which can produce N kinds of battle ships. The factory takes tiseconds to produce the