problem
solution
codes
//二分答案
//QAQ注意:起点和终点也是有石头的w
#include<iostream>
#include<algorithm>
#define maxn 100010
using namespace std;
int ll, n, m;
int a[maxn];
bool check(int x){
int t=0, co=0; //起点的石头不能搬走哦
for(int i = 1; i <= n+1; i++){
if(a[i]-a[t]<x)co++;//如果距离小于我二分的答案x,那么这块石头需要搬走
else t = i;//不然我就跳过来
}
if(co > m)return false;//如果要搬走的石头多于m块,那么这个解太大了
return true;
}
int main(){
cin>>ll>>n>>m;
for(int i = 1; i <= n; i++)cin>>a[i];
a[n+1] = ll;
sort(a,a+n+1); //排个序防炸输入数据
int l = 1, r = ll;
while(l <= r){
int mid = (l+r)/2;
if(check(mid))l = mid+1;
else r = mid-1;
}
cout<<r<<"\n";
return 0;
}
标签:NOIP2015,return,int,ll,石头,Luogu2678,maxn,include
From: https://blog.51cto.com/gwj1314/6043785