首页 > 代码库 > bzoj3969 [WF2013]Low Power
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; }
bzoj3969 [WF2013]Low Power
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。