标签:
一个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; }
CF D. One-Dimensional Battle Ships
标签:
原文地址:http://www.cnblogs.com/aoxuets/p/4712198.html