#include <iostream> #include <cstdio> #include <algorithm> using namespace std; long long rock[50005],l,n,m; bool check(long long d) { int total=0,i=1,j=1; while (i<n) { j=i+1; while (rock[j]-rock[i]<d&&j<n) { total++; j++; } i=j; } if (rock[n]-rock[n-1]<d) total++; return total<=m; } int main() { // freopen("in.txt","r",stdin); cin>>l>>n>>m; n+=2; for (int i=2;i<=n-1;i++) cin>>rock[i]; rock[n]=l; sort(rock+1,rock+n+1); long long left=1,right=rock[n],mid; while (right-left>1) { mid=(left+right)/2; //cout<<left<<" "<<mid<<" "<<right<<" "<<check(mid)<<endl; if (check(mid)) left=mid;else right=mid; } if (check(right)) cout<<right;else cout<<left; return 0; } 题意:一些石头排成一条线,第一个和最后一个不能去掉,其余的共可以去掉m块,要使去掉后石头间距的最小值最大。