给出两个长度为 $n$ 的数组 $a, b$
对于任意的 $a_i + b_j$, 求第 $k$ 大

不妨设 $a_i < a_{i + 1}, b_i < b_{i + 1}$

对于任意的 $a_i + b_j$, 可以得到这样的 $n ^ 2$ 个数

$$
\begin{matrix}
a_1 + b_1 & a_1 + b_2 & \cdots & a_1 + b_n \\
a_2 + b_1 & a_2 + b_2 & \cdots & a_2 + b_n \\
\vdots & \vdots & \ddots & \vdots \\
a_n + b_1 & a_n + b_2 & \cdots & a_n + b_n \\
\end{matrix}
$$

显然最小的数一定在第一列中
可以用一个 pair 存储矩阵中的每个元素
pair <a_i + b_j, j>
这样的话可以由改元素推出同行下列的元素
$first = a_i + b_j - b_j + b_{j + 1}$
$second = j + 1$

首先将第一列的元素对应的 pair 放入 priority_queue
每次弹出 fisrt 最小的元素,放入该元素的同行的下列元素

直至找到 $k$ 大

时间复杂度 O(nlogn)

a problem的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. Manjaro 使用基础

    一.pacman/yay 的基础命令 Manjaro 装好后,需要运行的第一条命令: sudo pacman -Syy ## 强制更新包数据 sudo pacman-mirrors --interac ...

  2. javascript之instanceof

    定义和用法 instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上. 语法: object instanceof construct ...

  3. 天梯赛 L2-023. 图着色问题

    题解:用dfs遍历图的每条边就好,这里注意要求颜色的个数为k #include <cstdio> #include <iostream> #include <cstrin ...

  4. 手把手教小白安装Erlang

    Erlang(['ə:læŋ])是一种通用的面向并发的编程语言,它有瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并发活动的编程语言和运行环境. Erlang官网:htt ...

  5. python多线程爬取斗图啦数据

    python多线程爬取斗图啦网的表情数据 使用到的技术点 requests请求库 re 正则表达式 pyquery解析库,python实现的jquery threading 线程 queue 队列 ' ...

  6. VIO的一些随笔

    大公司跑在手机的似乎都是滤波MSCKF那种,有优化的但似乎功耗不行.还有就是杂交的前端滤波后面在挂地图,反正国内的似乎就是SVO, VINS, ORBSLAM,MSCKF组合起来. 缺啥补啥,那个太烂 ...

  7. 正padding负margin实现多列等高布局(转)

    转自: 巧妙运用CSS中的负值 (http://www.webhek.com/post/2345qwerqwer.html) 代码来自: https://codepen.io/Chokcoco/pen ...

  8. stm32 FSMC-TFTLCD显示

    TFTLCD TFT液晶屏常用的通信模式主要有6800模式和8080模式,对于TFT彩屏通常都使用8080并口(简称80并口)模式 8080模式的读写时序其实跟LCD1602或者LCD12864的读写 ...

  9. springboot学习入门简易版一---springboot2.0介绍

    1.1为什么用springboot(2) 传统项目,整合ssm或ssh,配置文件,jar冲突,整合麻烦.Tomcat容器加载web.xml配置内容 springboot完全采用注解化(使用注解方式启动 ...

  10. Vue路由规则中定义参数

    Vue使用routerLinke定义参数的时候  路由规则中不需要更改任何属性. 路由其实就是我们在html中定义的锚点,点击这个连接跳转一个锚点.vue中的路由也是这个原理, 前提是路由必须创建在实 ...