标签:
5 3 1 2 8 4 9
3
题解:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 typedef long long LL; 8 const int MAXN=1e5+100; 9 int m[MAXN]; 10 int N,C; 11 bool js(int x){ 12 int t=m[0]; 13 int cnt=0; 14 for(int i=1;i<N;i++){ 15 if(m[i]-t>=x)cnt++,t=m[i]; 16 } 17 if(cnt>=C)return true; 18 else return false; 19 } 20 int erfen(int l,int r){ 21 int mid; 22 while(l<=r){ 23 mid=(l+r)/2; 24 if(js(mid))r=mid-1; 25 else l=mid+1; 26 } 27 return l; 28 } 29 int main(){ 30 while(~scanf("%d%d",&N,&C)){ 31 for(int i=0;i<N;i++)scanf("%d",m+i); 32 sort(m,m+N); 33 printf("%d\n",erfen(0,m[N-1]-m[0])); 34 } 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4963431.html