首页 > 其他分享 >跳石头2

跳石头2

时间:2024-12-11 22:54:04浏览次数:2  
标签:arr right int cnt 石头 two left

include<bits/stdc++.h>

using namespace std;
int two_k(int left,int right,vector&arr,int m){
if(left>right) return right;
int mid=left+(right-left)/2;
int n=arr.size();
vectorcur=arr;
int cnt=0;
int i=0;
while(i<n-1){
int j=i+1;
if(cur[j]-cur[i]<mid){
cur.erase(cur.begin()+j);
n--;
cnt++;
if(cnt>m) break;
} else{
i++;
}
}
if(cnt>m) {
return two_k(left,mid-1,arr,m);
}
else if(cnt<=m){
return two_k(mid+1,right,arr,m);
}
}
int main(){
int l,n,m;
cin>>l>>n>>m;
vectorarr;
arr.push_back(0);
while(n--){
int num;
cin>>num;
arr.push_back(num);
}
arr.push_back(l);
int ans=two_k(0,l,arr,m);
cout<<ans<<endl;
return 0;
}

标签:arr,right,int,cnt,石头,two,left
From: https://www.cnblogs.com/zsh260439/p/18601145

相关文章