LibreOJ 2423 跳石头
题目链接:LibreOJ 2423 跳石头
题目大意:
题解:
对最短跳跃距离进行二分答案即可。
#include <iostream>
using namespace std;
int res[60000];
int l, n, m, ans;
int get(int x) {
int t = 0;
int last = res[0];
for (int i = 1; i <= n + 1; i++) {
if (res[i] - last < x) {
t++;
} else {
last = res[i];
}
}
return t;
}
int main() {
cin >> l >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> res[i];
}
res[n + 1] = l;
int lift = 0, right = l;
while (lift <= right) {
int mid = (lift + right) / 2;
if (get(mid) <= m) {
ans = mid;
lift = mid + 1;
} else {
right = mid - 1;
}
}
cout << ans;
return 0;
}