在二分的基础上用差分,但只有30分(hack数据过了)

P2678 [NOIP2015 提高组] 跳石头

@[snownight10086](/user/1153600) ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn = 5e5 + 10; ll n, m, k, sum; ll a[maxn]; bool judge(ll x) { ll tot = 0, i = 0, u = 0;//用u来跳过那个值 while (i <= m) { i++; if (a[i] - u < x) { tot++; } else u = a[i]; } if (tot > k)return false; else return true; } int main() { cin >> n >> m >> k; for (ll i = 1; i <= m; i++) cin >> a[i]; a[m + 1] = n; ll o = 0, p = n; while (o <= p) { ll mid = (o + p) / 2; if (judge(mid)) { sum = mid; o = mid + 1; } else p = mid - 1; } cout << sum; return 0; } ```
by shoot_down @ 2024-02-08 20:02:54


|