1650: [Usaco2006 dec]river hopscotch Jumping stones

Source: Internet
Author: User

Title: There are n stones on the axis, the coordinates of the first stone is Di, now to jump from 0 to L, each time the bar jumps from one stone to the next. Now FJ allows you to remove the M-stone and ask how much the minimum value of the distance from the adjacent two stones will be when the M-stone is removed.

Input: 5 2 (l m N)
2 (D[i])
14
11

21st
17

Output: 4

Parse: Two-point enumeration of the minimum value between two stones X, if there are two stones between the distance is less than x, then delete the stone behind it. When done, if the number of stones removed is less than or equal to the number, it is established, otherwise, is not established.

#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;Long Longp1,m,mid,l,ans,n,l1[50001],d[50001],l2[50001],lef,righ;BOOLCheckLong Longx) {  Long LongK1,k2; if(x>l)return false; K1=m; P1=0;  for(intI=1; i<=n+1;++i) {if(d[i]-d[p1]<x) k1-=1; Elsep1=i; } K2=m; P1=n+1;  for(inti=n;i>=0;--i) {if(d[p1]-d[i]<x) k2-=1; Elsep1=i; }  if((k1>=0)|| (k2>=0))return true; Else return false;}intMain () {CIN>>l>>n>>m;  for(intI=1; i<=n;++i) cin>>D[i]; d[0]=0; Sort (d+1, d+1+N); D[n+1]=l; Lef=0; Righ=l+3;  while(lef<=righ)                                                                                                                                          { Mid= (Lef+righ)/2; if(check (mid) = =true) {Lef=mid+1; if(Mid>ans) ans=mid; }   Elserigh=mid-1; } cout<<ans<<Endl; return 0;}

PS: I code more complex, it is recommended to refer to more concise code.

1650: [Usaco2006 dec]river hopscotch Jumping stones

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.