POJ-3258 River Hopscotch
作者:互联网
River Hopscotch
给出n个点,最多能删除m个点,使得两个点之间的最短距离最大,问这个最大距离是多少
二分
直接二分答案,lower_bound,因为最后搜索到的是大的,所以要检查一下是否要减一,或者上界放大一点点,直接-1就行
检查的话就检查当前这个和前面里的最近的没被删掉的点的距离,如果小于当前确定的距离,就把这个点删掉
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
int num[maxn];
int n;
int query(int now)
{
int ans = 0, pre = 0;
for(int i=0; i<=n; i++)
{
if(num[i] - pre < now)
ans++;
else
pre = num[i];
}
return ans;
}
int main()
{
int len, m;
scanf("%d%d%d", &len, &n, &m);
for(int i=0; i<n; i++)
scanf("%d", &num[i]);
num[n] = len;
sort(num, num + n + 1);
int l = 1, r = len;
while(l < r)
{
int mid = l + (r - l) / 2;
if(query(mid) > m)
r = mid;
else
l = mid + 1;
}
if(query(l) > m) l--;
printf("%d\n", l);
return 0;
}
标签:3258,10,River,const,int,ll,POJ,query,include 来源: https://www.cnblogs.com/dgsvygd/p/16191514.html