求教

P2678 [NOIP2015 提高组] 跳石头

我不懂
by Ykimna @ 2019-01-25 16:56:53


@[my亦客♂](/space/show?uid=107297) # 红名大佬!!
by 闻染 @ 2019-01-25 17:01:27


头像好评
by suyiheng @ 2019-01-25 17:03:04


```cpp #include<iostream> #include<cstdio> using namespace std; const int ok=50005; int l,n,m,a[ok],ans; bool check(int x) { int tot=0,i=0,now=0; while(i<n+1) { i++; if(a[i]-a[now]<x) tot++; else now=i; } return tot<=m; } int main() { cin>>l>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; a[n+1]=l; int low=1,up=l,mid=0; while(low<=up) { mid=(low+up)/2; if(check(mid)) { ans=mid; low=mid+1; } else up=mid-1; } cout<<ans<<endl; return 0; } ```
by Hexarhy @ 2019-01-25 17:07:00


|