#include <iostream>
#include <cstdio>
#define MAXN 100000
using namespace std;
int l,n,m,ans;
int stone[MAXN];
bool check(int mins)
{
int k=0,count=0;
for (int i=1;i<=n;i++){
if (stone[i]-k<mins){
count++;
if (count>m){
return false;
}
}else{
k=stone[i];
}
}
return true;
}
int main()+
{
cin>>l>>n>>m;
stone[0]=0;
for (int i=1;i<=n;i++){
cin>>stone[i];
}
stone[++n]=l;
int L=1,R=l,mid;
while (L<R){
mid=(L+R)/2;
if (check(mid)){
ans=mid;
L=mid+1;
}else{
R=mid;
}
}
cout<<ans<<endl;
}
NOIP 2015提高组 跳石头
区间取石问题求解
最新推荐文章于 2025-04-13 19:51:37 发布
本文介绍了一种解决区间取石问题的算法实现。通过二分查找法确定最小步长,确保在限定次数内完成任务。该算法适用于路径规划、资源分配等场景。

2899

被折叠的 条评论
为什么被折叠?



