2015 UESTC 搜索专题D题 基爷的中位数 二分
基爷的中位数
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/61
Description
现在,基爷希望聪明的你能用一个简单的程序求出这 C2N 个数的中位数!
Input
每组数据,第一行一个整数 N,第二行给出 N 个整数 X1,X2,...,XN ( |Xi|≤1,000,000,000; 3≤N≤100,000 )
Output
按要求输出中位数,每个数占一行。
Sample Input
1 3 2 4
3
1 10 2
Sample Output
8
HINT
当这 C2N 个数的个数为偶数 M 的时候,取第 ⌊M2⌋ 个最小的数作为中位数 ( 别问为什么,这就是基爷的中位数! )
题意
题解:
二分答案枚举中位数,然后再二分 a[i]-a[j]=二分的那个数的值在哪儿
nloglog的做法
nlog就要用two pointer去优化
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll a[maxn],n;
ll tmp; int main()
{
while(scanf("%lld",&n)!=EOF)
{
for(int i=;i<n;i++)
scanf("%lld",&a[i]);
tmp=n*(n-)/;
sort(a,a+n);
ll l=,r=;
while(l+<r)
{
ll mid=(l+r)>>;
ll ans=;
for(int i=;i<n;i++)
{
ans+=a+n-lower_bound(a+i+,a+n,a[i]+mid);
}
if(ans<=tmp/)
r=mid;
else
l=mid;
}
printf("%lld\n",l);
} }
2015 UESTC 搜索专题D题 基爷的中位数 二分的更多相关文章
- 2015 UESTC 搜索专题C题 基爷与加法等式 爆搜DFS
基爷与加法等式 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
- 2015 UESTC 搜索专题N题 韩爷的梦 hash
韩爷的梦 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descrip ...
- 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜
Eight Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...
- 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp
秋实大哥の恋爱物语 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...
- 2015 UESTC 搜索专题E题 吴队长征婚 爆搜
吴队长征婚 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Descri ...
- 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索
邱老师降临小行星 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
- 2015 UESTC 搜索专题M题 Palindromic String 马拉车算法
Palindromic String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/s ...
- 2015 UESTC 搜索专题J题 全都是秋实大哥 kmp
全都是秋实大哥 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Desc ...
- 2015 UESTC 搜索专题A题 王之迷宫 三维bfs
A - 王之迷宫 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
随机推荐
- UNDO自我理解总结
[场景] 当在更新数据的时候,发现更新的值写错了,这时就需要将已经更新的地方恢复到原始数据. [基本概念] 在更新的过程中,Oracle会将原始的数据都放入到UNDO里,这样当以上情况发生后,就可以从 ...
- 端口扫描———nmap
nmap教程之nmap命令使用示例(nmap使用方法) 浏览:8268 | 更新:2014-03-29 17:23 Nmap是一款网络扫描和主机检测的非常有用的工具.Nmap是不局限于仅仅收集信息和枚 ...
- Binary Tree Zigzag Level Order Traversal——关于广度优先的经典面试题
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...
- jquery重置
在使用jquery时要先引用 <script type="text/javascript" src="/Themes/Default/Js/jquery-1.11. ...
- java EE : http 协议响应头部信息验证
一 location :***** 302 重定向 private void doWork(HttpServletRequest req, HttpServletResponse resp ...
- Three.js基础探寻八——法向材质与材质的纹理贴图
4.法向材质 法向材质可以将材质的颜色设置为其法向量的方向,有时候对于调试很有帮助. 法向材质的设定很简单,甚至不用设置任何参数: new THREE.MeshNormalMaterial() 材质的 ...
- 【LOJ】 #2015. 「SCOI2016」妖怪
题解 这道题教会我很多东西,虽然它是个傻逼三分 1.long double的运算常数是巨大的 2.三分之前的界要算对!一定要算准,不要想一个直接写上! 3.三分100次也就只能把精度往里推20多位,可 ...
- Vibrator震动
今天又学一招: Android手机中的震动由Vibrator实现.设置震动事件,需要知道其震动的时间长短.震动的周期等. 在 Android Vibrator中,震动的时间以毫秒计算(1/1000秒) ...
- 20169211《Linux内核原理与分析》第一周作业
本科期间,学校开设过linux相关的课程,当时的学习方式主要以课堂听授为主.虽然老师也提供了相关的学习教材跟参考材料,但是整体学下来感觉收获并不是太大,现在回想起来,主要还是由于自己课下没 ...
- ZOJ 3957 Knuth-Morris-Pratt Algorithm
暴力. #include<bits/stdc++.h> using namespace std; ]; int main() { int T; scanf("%d",& ...