给出两个长度为 $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. jquery封装的方法

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  2. ifconfig介绍

    [root@controller01 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNK ...

  3. MySQL多表关联查询数量

    //多表关联查询数量select user, t1.count1, t2.count2from user tleft join ( select user_id, count(sport_type) ...

  4. python学习笔记(CMD运行文件并传入参数)

    好久没更新博客了 最近换了份新工作 有时间来整理一篇 在命令行CMD中执行文件过程中如何传入并识别参数 # -*- coding: utf-8 -*- # CMD运行类 # 作者: # 时间: 201 ...

  5. 【转载】Request对象的作用以及常见属性

    Request对象是Asp.Net应用程序中非常重要的一个内置对象,其作用主要用于服务器端获取客户端提交过来的相应信息,比较常用的有使用Requset对象获取用户提交的html表单信息,Request ...

  6. jq的ajax方法

    相较与js异步对象的繁琐,jq的ajax对象结构更加清晰 一:ajax对象简述 ajax(Asynchronous JavaScript and XML),异步的xml和js对象,主要用于在不刷新全局 ...

  7. ES6-promise实现异步请求

    一.Promise是什么 简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果. ES6规定,Promise对象是一个构造函数,用来生成Promise实例.Promise构 ...

  8. 在pivotal cloud foundry上申请账号和部署应用

    Created by Wang, Jerry, last modified on Jul 04, 2016 URL: http://run.pivotal.io/ maintain your mobi ...

  9. nginx的gzip模块详解以及配置

    文章来源 运维公会:nginx的gzip模块详解以及配置   1.gzip模块作用 gzip这个模块无论在测试环境还是生产环境都是必须要开启,这个模块能高效的将页面的内容,无论是html或者css.j ...

  10. 基于FTP 的本地Yum服务器配置

    服务器端 环境如下 Vmware14CentOS 7.6 192.168.20.81 server 192.168.20.81 client 1.配置yum源 mount /dev/cdrom /me ...