NOIP 2015 D2T1
题解:二分答案(最小跳跃距离),每次O(n)check,凡是中间的石子都移走,如果移走的数量大于m就减小mid,否则增大mid。
1A,贼稳(^_^)。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=5e4+5;
int d[MAXN],L,n,m;
inline int read() {
int x=0;char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
inline bool cck(int mid) {
int t=0,last=0;
for (int i=1;i<=n;++i) {
if (d[i]-last<mid) ++t;
else last=d[i];
if (t>m) return false;
}
return true;
}
int main() {
// freopen("bzoj 1650.in","r",stdin);
L=read(),n=read(),m=read();
for (int i=1;i<=n;++i) d[i]=read();
d[0]=0,d[++n]=L;
sort(d,d+n);
int l=0,r=L,ans;
while (l<=r) {
int mid=(l+r)>>1;
if (cck(mid)) ans=mid,l=mid+1;
else r=mid-1;
}
printf("%d\n",ans);
return 0;
}