bzoj4525: [Usaco2016 jan]angry cows

Source: Internet
Author: User

bzoj4525: [Usaco2016 jan]angry cows time limit:1 Sec Memory limit:128 MB
Submit:90 solved:71
[Submit] [Status] [Discuss] Description Cow Bessie designed a game: "Angry cows". The prototype of the game is: there are some explosive haystack distributed in some coordinates of a number axis, play a home slingshot to launch a cow to the number line. The shock wave of a cow hitting the axis will cause a nearby haystack to explode. The goal of the game is to play home some cows blow up all the haystack. There are n haystack in the different positions of the axis, coordinates of x1,x2,...., xn. If the player launches the cow to coordinate X with energy R, it will detonate the haystack in radius r and within, i.e. the haystack of the coordinate range [x−r,x+r] will explode. Now there are K-head cows, each cow's energy is r, please calculate if you want to detonate all the haystack, what is the minimum r?

Input first line: 2 integers N (1≤n≤50,000) and K (1≤K≤10). There are n rows, one integer per line: x1,x2,..., xn, range in [0 ... 1,000,000,000].

Output

Outputs the smallest possible r.

Sample Input7 2
20
25
18
8
10
3
1
Sample Output5HINT Source

Two-point answer + greedy verification

#include <bits/stdc++.h>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineN 50001using namespaceStd;inlineintRead () {intx=0, ch=GetChar ();  while(ch<'0'|| Ch>'9') ch=GetChar ();  while(ch>='0'&&ch<='9') x=x*Ten+ch- -, ch=GetChar (); returnx;}intMain () {intn,k,s[n],l,r,mid,last,now,ans=2147483647; scanf ("%d%d",&n,&k); Rep (I,1, N) s[i]=read (); Sort (S+1, s+1+N); L=1; R=500000000;  while(l<=r) {Mid= (l+r) >>1; now=0; Rep (I,1, K) { Last=s[now+1];  while(s[now+1]-last<=mid*2&&now<n) + +Now ; }          if(now>=n) Ans=min (ans,mid), r=mid-1;ElseL=mid+1; } printf ("%d", ans);}
View Code

bzoj4525: [Usaco2016 jan]angry cows

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.