首页 > 代码库 > NOIP201508跳石头(C++)

NOIP201508跳石头(C++)

#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=50005;
int a[maxn],n,m,ans;
bool check(int x)
{
int sum,last;
sum=0;last=0;
for (int i=1;i<=n;i++)
{
if (a[i]-last<x) { sum+=1;continue;}
last=a[i];
}
if (sum>m) return 0;
return 1;
}
int main()
{
int L,R,mid;
scanf("%d%d%d\n",&L,&n,&m);
for (int i=1;i<=n;i++) scanf("%d\n",&a[i]);
n+=1;
a[n]=L;R=L;
ans=L=0;
while (L<=R)
{
mid=L+(R-L)/2;
if (check(mid)) { ans=mid;L=mid+1; }
else R=mid-1;
}
printf("%d",ans);
return 0;
}

NOIP201508跳石头(C++)