P2678 [NOIP 2015 提高组] 跳石头
点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=50010;
int n,m;
LL L;
int a[N];
bool check(int x)
{
int cnt=0;
int pos=0;
for(int i=1;i<=n+1;i++){
if(a[i]-pos<x){
cnt++;
}else{
pos=a[i];
}
}
return m>=cnt;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>L>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
a[n+1]=L;
int l=1,r=L;
int ans=0;
while(l<=r){
int mid=l+(r-l)/2;
if(check(mid)){
l=mid+1;
ans=mid;
}else{
r=mid-1;
}
}
cout<<ans<<endl;
return 0;
}

浙公网安备 33010602011771号