P2678 [NOIP2015 提高组] 跳石头
本体可以用二分法,再对所猜的数进行合法判断,因为所求最短距离的最大值,所以当数不合法(所需移走的石头数>可以移走的数量) 时向小的一边猜,如果合法(所需移走的石头数<=可以移走的数量)时向大的一边猜。
判断合法函数
bool check(int x){ int last=0,temp=0; for(int i=1;i<=n+1;i++) { if (a[i] - last < x) { temp++; } else { last = a[i]; } } if(temp>m) return false; else return true; }
主函数中的二分法
int main() { cin>>L>>n>>m; memset(a,0,n); for(int i=1,j=0;i<=n;i++,j++){ cin>>*(a+i); } a[n+1]=L; int l=0,r=L; wh