Aggressive cows

Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000).

His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ want to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance?
Input
* Line 1: Two space-separated integers: N and C 

* Lines 2..N+1: Line i+1 contains an integer stall location, xi
Output
* Line 1: One integer: the largest minimum distance
Sample Input
5 3
1
2
8
4
9
Sample Output
3
Hint
OUTPUT DETAILS: 

FJ can put his 3 cows in the stalls at positions 1, 4 and 8, resulting in a minimum distance of 3. 

Huge input data,scanf is recommended.

Here is a summary of the common template properties of Can you solve this equation? Cable Master Agressive Cows.

1. Set the left and right boundaries of the bisection, or even directly set l=0, r=INF, because the complexity of the bisection is very low, logn, so it is easy to find the upper and lower bounds that conform to the logic of the problem, and it will not affect the operation time. cause too much burden;

2. The loop of whie(rl>EPS) is the core code of solving the problem logic, which expresses the process of dichotomy;

3. The judge function is actually the most individual part of each topic, and different judgment conditions are set in combination with specific topics to determine the change process of the upper and lower bounds depending on the judgment conditions.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325474677&siteId=291194637