# 51Nod - 1521 STL +二分

## 代码：

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;

int q[MAXN];
set <int> :: iterator it;

int main() {
int n, m, k, a;
scanf("%d%d%d%d", &n, &k, &a, &m);
for (int i = 1; i <= m; i++)
scanf("%d", &q[i]);
set <int> st;
int cnt = (n + 1) / (a + 1);
st.insert(0); st.insert(n + 1);
for (int i = 1; i <= m; i++) {
if (st.find(q[i]) != st.end()) continue;
it = st.upper_bound(q[i]);
int r = *it, l = *(--it);
// printf("%d %d\n", l, r);
int t1 = (r - l) / (a + 1), t2 = (r - q[i]) / (a + 1) + (q[i] - l) / (a + 1);
cnt -= (t1 - t2);
// cout << cnt << endl;
if (cnt < k) {
printf("%d\n", i);
return 0;
}
st.insert(q[i]);
}
puts("-1");
return 0;
}


#### 51Nod-1521-一维战舰

2016-10-17 19:56:10

#### 51nod 1521 一维战舰

2016-10-22 17:06:34

#### 51Nod-1981-如何愉快地与STL玩耍

2018-01-05 19:15:14

#### 51nod 1686 二分+尺取法

2017-04-12 22:08:01

#### C++ STL 二分查找函数(lower_bound 和 upper_bound)

2018-02-15 17:04:48

#### STL中提供-二分查找算法(binary_search lower_bound upper_bound equal_range)

2011-10-18 09:09:26

#### [牛顿法 || 二分] BZOJ 1213 [HNOI2004]高精度开根 & 51Nod 1166 大数开平方

2016-07-08 19:50:24

#### 51Nod-1799-二分答案

2017-05-30 21:05:58

#### STL 二分查找三兄弟（lower_bound(),upper_bound(),binary_search())

2014-11-20 22:30:40

#### STL中与二分查找相关的4个函数

2015-04-18 10:39:55