bzoj3969 [WF2013]Low Power
阿新 • • 發佈:2017-06-02
lose col for esp bzoj3 alt type color target
傳送門: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; typedefView Codelong 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