标签:
Description
Input
Output
Sample Input
5 3 1 2 8 4 9
Sample Output
3
Hint
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 using namespace std; 6 const int INF=1e9+7; 7 8 int N,m; 9 int a[100005]; 10 11 bool C(int d) 12 { 13 int last=1; 14 for(int i=1;i<m;i++) 15 { 16 int crt=last+1; 17 while(crt<=N && a[crt]-a[last]<d) 18 { 19 crt++; 20 } 21 if(crt==N+1) 22 return false; 23 last=crt; 24 } 25 return true; 26 } 27 28 int main() 29 { 30 int i,j; 31 while(scanf("%d %d",&N,&m)!=EOF) 32 { 33 for(i=1;i<=N;i++) 34 scanf("%d",&a[i]); 35 sort(a+1,a+N+1); 36 int lb=0,ub=INF; 37 while(ub-lb>1) 38 { 39 int mid=(lb+ub)/2; 40 if(C(mid)) 41 lb=mid; 42 else 43 ub=mid; 44 } 45 printf("%d\n",lb); 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/cyd308/p/4693662.html