欢迎光临
我们一直在努力

P2678 [NOIP 2015 提高组] 跳石头 二分解决

#include <bits/stdc++.h>

using namespace std;

int L,N,m;
const int n=5e4+9;
int a[n];
int check(int mid)
{
int res=0;
int lst=0;
for(int i=1;i<=N;i++)
{
if(a[i]-a[lst]<mid)
{
res++;
continue;
}
lst=i;

}
if(L-a[lst]<mid) res++;
return res;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>L>>N>>m;
for(int i=1;i<=N;i++)
{
cin>>a[i];
}
long long l=0;
long long r=1e9+5;
while(l+1!=r)
{
long long mid=(l+r)/2;
if(check(mid)<=m)l=mid;
else r=mid;
}
cout<<l;
return 0;
}

记住模板,猛抓二分思维解决最最值问题(没打错)

赞(0)
未经允许不得转载:171主机测评 » P2678 [NOIP 2015 提高组] 跳石头 二分解决
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址