bzoj3969 [WF2013]Low Power

Posted 逢山开路 遇水架桥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj3969 [WF2013]Low Power相关的知识,希望对你有一定的参考价值。

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3969

【题解】

二分答案x,贪心选取,如果选取了i个,有j对,那么要满足i<=2*j*k(不然有数就没位置放了)

技术分享
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 2e6 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, k, N; 
int a[M]; 

inline bool chk(int x) { 
    int times = 0;
    for (int i=1; i<=N; ++i) { 
        if(i-1 > 2*times*k) return false; 
        if(i <= N && a[i+1] - a[i] <= x) ++i, ++times; 
        if(times == n) return 1; 
    }
    return false;
}
         
int main() {
    cin >> n >> k; N = 2*n*k;
    for (int i=1; i<=N; ++i) scanf("%d", a+i);
    sort(a+1, a+N+1);
    int l = a[2] - a[1], r = 1e9, ans;
    while(1) {
        if(r-l <= 3) {
            for (int i=l; i<=r; ++i) {
                if(chk(i)) {
                    ans = i;
                    break;
                }
            }
            break;
        }
        int mid = l+r>>1;
        if(chk(mid)) r = mid;
        else l = mid;
    }
    cout << ans << endl; 
    return 0;
}
View Code

 

以上是关于bzoj3969 [WF2013]Low Power的主要内容,如果未能解决你的问题,请参考以下文章

[bzoj3955] [WF2013]Surely You Congest

bzoj3953: [WF2013]Self-Assembly

[bzoj3953] [WF2013]Self-Assembly

BZOJ3971 [WF2013]Матрёшка

题目清单(更新至12月17日 10:52)

BZOJ 4078: [Wf2014]Metal Processing Plant