洛谷 P3853 [TJOI2007]路标设置
生活随笔
收集整理的這篇文章主要介紹了
洛谷 P3853 [TJOI2007]路标设置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
路標(biāo)設(shè)置
二分枚舉”空曠指數(shù)“, 做法與跳石頭類似。
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; //Mystery_Sky // #define M 10000100 #define INF 0x7f7f7f7f #define ll long long ll l, r, mid; int L, n, k; int a[M]; inline bool check(ll ans) {int last = 0, cnt = 0;for(int i = 2; i <= n; i++) {while (a[i] - last > ans) {cnt++;last += ans;}last = a[i];}return cnt <= k; }int main() {scanf("%d%d%d", &L, &n, &k);a[0] = 0;for(int i = 1; i <= n; i++) scanf("%d", &a[i]);a[++n] = L;sort(a, a+n+1);l = 0, r = INF;while(l < r) {mid = l + (r - l) /2;if(check(mid)) r = mid;else l = mid + 1;}printf("%lld\n", l);return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/Benjamin-cpp/p/10877905.html
總結(jié)
以上是生活随笔為你收集整理的洛谷 P3853 [TJOI2007]路标设置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Laravel Conf China 2
- 下一篇: Mybatis源码分析--Mapper接