码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj3969 [WF2013]Low Power

时间:2017-06-02 22:08:42      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:str   fine   problem   ++   img   ide   .com   bre   return   

传送门: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

标签:str   fine   problem   ++   img   ide   .com   bre   return   

原文地址:http://www.cnblogs.com/galaxies/p/bzoj3969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!