答案二分,lowerbound,upperbound
2017-03-05 12:41
169 查看
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; typedef long long LL; const int maxn = (int) 1e5 + 7; int A[maxn]; int d; 基本思路: 由于绝对值在0到max(A[i])(i>=0,i<n)中 所以只要在0-1000000000之间二分=30次就可以找到答案 二分的判断是比较所有情况中的小于目前举出的中位数的个数 这个类举得复杂度为n*logn=17*100000/2 bool check(int x,int n) { LL cnt = 0; for (int i = 0; i < n; i++) { cnt += n - (lower_bound(A + i, A + n, x + A[i]) - (A)); } return cnt <= d; } int main() { #ifndef Local freopen("in.txt", "r", stdin); #endif int n; while (cin >> n) { for (int i = 0; i<n; i++) { scanf("%d", A+i); } sort(A,A+n); d = n*(n - 1) / 2; if (d % 2) { d = d >> 1; } else { d = (d + 1) >> 1; } int left = A[0],right=A[n-1]-A[0]+1; while (left < right) { int mid = (left + right) >> 1; } } return 0; }
相关文章推荐
- 二分答案,lowerbound
- 【二分答案+贪心】UVa 1335 - Beijing Guards
- [AGC007E]Shik and Travel-动态规划-二分答案
- 【bzoj3316】JC loves Mkk 二分答案+单调队列
- 【NOIP2015】【bzoj4326】运输计划 LCA+差分+二分答案
- POJ 3122 Pie【二分答案】
- Luogu-2680 (二分答案+树上差分)
- Gym - 101490E Charles in Charge【最短路+二分答案】
- [bzoj4443][Scoi2015]小凸玩矩阵(二分答案+二分图最大匹配)
- hihocoder 1139 二分答案+BFS求最短路
- CF #262 (DIV2) C . Present (二分答案)
- luogu1083【2012提高】借教室(二分答案+差分前缀和)
- POJ 3525 二分答案,推进多边形和半平面交
- poj2728 Desert King(最优比率生成树,二分答案+prim)
- 【二分答案】收入计划
- 再解“书的复制” 二分答案+贪心
- POJ 3208 Apocalypse Someday 二分答案+数位DP
- NKOJ 2650 (SDOI 2011) 消防(树的直径+DP+单调队列/二分答案)
- NOIP2011 DAY2 T2 浅谈二分答案
- BZOJ 2097 Exercise 奶牛健美操 二分答案+树形DP+贪心