Gym 101064 D Black Hills golden jewels (二分)
题目链接:http://codeforces.com/gym/101064/problem/D
问你两个数组合相加的第k大数是多少。
先sort数组,二分答案,然后判断其正确性(判断过程是枚举每个数然后二分)。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
LL a[N], k, n; bool judge(LL val) {
LL cnt = ;
for(int i = ; i <= n; ++i) {
LL pos = (LL)(upper_bound(a + , a + n + , val - a[i]) - a);
if(pos > (LL)i)
cnt += n - pos + ;
else
cnt += n - pos;
}
cnt /= ;
return (n - )*n/ - k >= cnt;
} int main()
{
while(~scanf("%lld %lld", &n, &k)) {
for(int i = ; i <= n; ++i) {
scanf("%lld", a + i);
}
sort(a + , a + n + );
LL l = a[] + a[], r = a[n] + a[n - ];
while(l < r) {
LL mid = (l + r) / ;
if(judge(mid)) {
r = mid;
} else {
l = mid + ;
}
}
printf("%lld\n", l);
}
return ;
}
Gym 101064 D Black Hills golden jewels (二分)的更多相关文章
- Gym 101064 D Black Hills golden jewels 【二分套二分/给定一个序列,从序列中任意取两个数形成一个和,两个数不可相同,要求求出第k小的组合】
D. Black Hills golden jewels time limit per test 2 seconds memory limit per test 256 megabytes input ...
- D. Black Hills golden jewels 二分答案 + 二分判定
http://codeforces.com/gym/101064/problem/D 题目是给定一个数组,如果两两组合,有C(n, 2)种结果,(找出第一个大于等于第k大的结果) 思路, 二分答案va ...
- Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
- Gym - 101002K:YATP (树分治+二分+斜率优化)
题意:给定带点权边权的树,定义路径的花费=路径边权和e+起点点权w[s]*终点点权w[t].N<2e5,e,w<1e6: 思路:首先,需要树分治. 然后得到方程dp[i]=min{ dis ...
- Gym - 100283F Bakkar In The Army(二分)
https://vjudge.net/problem/Gym-100283F 题意: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 .... 给出这样的序列,然后给出一个n,计算从1 ...
- Gym 101128J Saint John Festival(凸包 + 二分判点和凸包关系)题解
题意:给你一堆黑点一堆红点,问你有最多几个黑点能找到三个红点,使这个黑点在三角形内? 思路:显然红点组成的凸包内的所有黑点都能做到.但是判断黑点和凸包的关系朴素方法使O(n^2),显然超时.那么我现在 ...
- gym 101064 G.The Declaration of Independence (主席树)
题目链接: 题意: n个操作,有两种操作: E p c 在序号为p的队列尾部插入c得到新的队列,序号为i D p 查询并删除序号为p的队列顶部的元素,得到序号为i的新队列 思路: 需要查询 ...
- GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树
G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...
随机推荐
- [Swift 语法点滴]—— Struct Vs Class
摘自:stackoverflow.com/questions/24232799/why-choose-struct-over-class Structure instances are always ...
- memcached缓存雪崩现象及解决办法
1)什么是缓存雪崩?场景:一个访问很大的文章(论坛之类)的网站,使用memcached缓存用户查询过的文章.设置的缓存过期时间为6小时,所以没过6小时,缓存就会失效并重建一遍 问题:过六小时时,一部分 ...
- Linux 系统时钟(date) 硬件时钟(hwclock)
/********************************************************************* * Linux 系统时钟(date) 硬件时钟(hwclo ...
- android 自定义组件-带图片的textView
1. 定义属性 <?xml version="1.0" encoding="utf-8"?> <resources> <decla ...
- Jquery Mobile设计Android通讯录第二章
本文是jQuery Mobile设计Android通讯录系统教程的第二篇,在上一篇教程中(http://publish.itpub.net/a2011/0517/1191/000001191561.s ...
- 网页计算器,(类,隐藏域,style=display:block等)
第一个文件:表单文件 <html> <head><meta http-equiv="content-type" content="text/ ...
- Axis,axis2,Xfire以及cxf对比
http://ws.apache.org/axis/ http://axis.apache.org/axis2/java/core/ http://xfire.codehaus.org/ http:/ ...
- JDBC数据源(DataSource)的简单实现
数据源技术是Java操作数据库的一个很关键技术,流行的持久化框架都离不开数据源的应用. 数据源提供了一种简单获取数据库连接的方式,并能在内部通过一个池的机制来复用数据库连接,这样就大大减少创建数据 ...
- android操作文件
Android中读取/写入文件的方法,与Java中的I/O是一样的,提供了openFileInput()和openFileOutput()方法来读取设备上的文件.但是在默认状态下,文件是不能在不同的程 ...
- delphi7如何实现 科学计数的转换。 比如我输入2,触发之后会转换成2.000000E+00.求赐教
uses SysUtils; function StrToExp(s: string): string;var f: Extended;begin f := StrToFloat(s); Result ...