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