#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
//#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int l, n, m;
int a[50010];
bool check(int x) //x表示最短跳跃路径
{
int tot = 0; //tot记录以x为最短跳跃路径时需要搬走几块石头
int now = 0; //模拟一个人现在在哪块石头
int i = 0; //i代表下一块石头的编号
while (i < n+1) //注意,石头数量从1~n+1
{
i++;
if (a[i] - a[now] < x)//判断要跳到的位置与当前位置之间的距离与x的大小
tot++; //如果比x小,x就不能是最短路径了,所以把这块石头搬走
else
now = i; //否则的话就跳到这块石头上
}
if (tot > m)return false; //组委会至多移走岩石m个,大于m所以方案不成立
else return true;
}
int main()
{
cin >> l >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int ans;
a[n+1] = l; //终点的石头是要跳到的
int left = 1, right=1e9+10;
while (left <= right) //注意边界问题
{
int mid = (left + right) >> 1;
if (check(mid))
{
ans = mid; //满足条件的mid是可以的
left = mid+1; //题目要求最大值,我们往后找
}
else
{
right = mid - 1;//不满足条件的mid肯定不行,我们不记录进ans
}
}
cout << ans << endl;
}
P2678 跳石头
于 2020-08-11 14:03:38 首次发布