NYOJ 586 crazy ox

Source: Internet
Author: User

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
         
          

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.