给出两个长度为 $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. Notepad++连接VMWare中Linux只能看到/root目录

    如下图,使用SFTP协议连接,用root用户登录后,我一开始只能看到root下的文件.稍作修改,把下面的“Initial remote directory”设置成“/”就可以看到根目录了.

  2. DotNet 使用阿里云媒体转码服务

    公司项目中一部分文件放到了阿里云 OSS 上,其中有些音频文件是 amr 类型的,在后期使用的时候比较麻烦,所以需要转换成 mp3 的文件,方便以后使用.本来想使用 ffmpeg 处理,但由于文件都存 ...

  3. .netCore 动态织入

    using Microsoft.Extensions.DependencyInjection; using System; using System.Reflection; namespace Aop ...

  4. 在我的电脑中删除wps云文档图标

    在我的电脑中删除wps云文档图标 右键点击win10左下角选择运行,输入regedit打开注册表后,找到以下注册表路径: HKEY_CURRENT_USER\Software\Microsoft\Wi ...

  5. iOS - App上架流程(复习+已用xcode8)

    一.前言: 今天又要上架一款APP,顺便来复习一下APP上架流程 下面就来详细讲解一下具体流程步骤. 二.准备: 一个已付费的开发者账号(账号类型分为个人(Individual).公司(Company ...

  6. js垃圾回收及内存泄漏

    js垃圾回收 js能够自动回收申请却未使用的内存,由于每次清除需要的性能较大,不是时时在刷新,而是每隔一段时间才进行一次. 回收的两种方式 标记清除(常用) 在内存中先标记变量,然后清除那些那些进入环 ...

  7. CSS选取第一个、最后一个、偶数、奇数、第n个标签元素

    1.first-child first-child表示选择列表中的第一个标签.例如:li:first-child{background:#fff} 2.last-child last-child表示选 ...

  8. UI5-技术篇-Navigation And Routing

    主要记录下Router设置过程中出现的几个问题 1.View 首页设置 controlId 2.Manifest设置 2.1设置启动页 2.2设置默认配置 2.3设置Targets 首页设置 子页设置 ...

  9. 【转载】内联函数 —— C 中关键字 inline 用法解析

    转载地址:https://blog.csdn.net/zqixiao_09/article/details/50877383 一.什么是内联函数 在C语言中,如果一些函数被频繁调用,不断地有函数入栈, ...

  10. idou老师教你学istio30:Mixer Redis Quota Adapter 实现和机制

    1. 配置 1.1参数 1.2 Params.Quota 1.3Params.Override 1.4Params.QuotaAlgorithm 速率限制的算法: Fixed Window 算法每个时 ...