Mad cow time limit: ms | Memory limit:65535 KB Difficulty:4
-
Describe
- The farmer John built a long corral that consisted of N (2 <= n <= 100,000) compartments, numbered X1,..., XN (0 <= XI <= 1,000,000,000).
However, John's C (2 <= C <= N) Cows do not like this layout, and a few cows in a compartment, they will be fighting. In order not to let the cows hurt each other. John decided to allocate a compartment for the cows so that the minimum distance between any two cows is as large as possible, so what is the maximum minimum distance?
-
-
Input
-
-
There are multiple sets of test data, ending with EOF. First line: space-delimited two integers n and c second row-line n+1: The position of Xi is indicated separately
-
-
Output
-
-
each set of test data outputs an integer that satisfies the maximum minimum value of the test instructions and takes note of the newline.
-
-
Sample input
-
-
5 312849
-
-
Sample output
-
3
Exercises
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7typedefLong LongLL;8 Const intmaxn=1e5+ -;9 intM[MAXN];Ten intn,c; One BOOLjsintx) { A intt=m[0]; - intCnt=0; - for(intI=1; i<n;i++){ the if(m[i]-t>=x) cnt++,t=M[i]; - } - if(CNT>=C)return true; - Else return false; + } - intErfen (intLintR) { + intmid; A while(l<=R) { atMid= (L+R)/2; - if(JS (mid)) r=mid-1; - ElseL=mid+1; - } - returnl; - } in intMain () { - while(~SCANF ("%d%d",&n,&C)) { to for(intI=0; i<n;i++) scanf ("%d", m+i); +Sort (m,m+N); -printf"%d\n", Erfen (0, m[n-1]-m[0])); the } * return 0; $}
Mad Cow (two points)