Crazy ox time limit: 1000 MS | memory limit: 65535 KB difficulty: 4
-
Description
-
Farmer John built a long barrier, which contains 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 when a few cows are placed in a compartment, they are about to fight. In order not to let the ox hurt each other. John decided to allocate his own compartment for the ox so that the minimum distance between any two cows is as large as possible. What is the maximum and minimum distance?
-
Input
-
There are multiple groups of test data, ending with EOF.
First line: two integers N and C separated by Spaces
The second line -- line N + 1 indicates the position of xi respectively.
-
Output
-
Each group of test data outputs an integer that satisfies the maximum and minimum values of the question. Note the line feed.
-
Sample Input
-
5 312849
-
Sample output
-
3
-
Binary + greedy!
-
AC code:
-
# Include
# Include
# Define deusing namespace std; int num [100005], n, c; int judge (int x) {int cnt = 1, temp = num [0], I; for (I = 1; I
= X) {cnt ++; // Add 1 temp = num [I]; if (cnt> = c) // if the average shortest length is x, return 1;} return 0;} int get_ans () {int l = 0, r = num [n-1]-num [0], mid; while (l <= r) {mid = (l + r)/2; if (judge (mid) l = mid + 1; elser = mid-1 ;} return L-1;} int main () {int I; while (~ Scanf ("% d", & n, & c) {for (I = 0; I