当前位置:网站首页>【acwing】786. 第k个数
【acwing】786. 第k个数
2022-07-07 07:46:00 【percation】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int q[N];
int n,k;
int qs(int l, int r, int k){
if(l == r) return q[l];
int i = l - 1, j = r + 1, x = q[(l + r)/2];
while(i < j){
while(q[++i] < x) ;//实现左区间向右边前进,右区间向左边前进
while(q[--j] > x) ;
if(i < j) swap(q[i],q[j]);
}
int s1 = j - l + 1;//找到当时分界点在区间的位置,因区间从0开始,所以要加1
if(k <= s1)//当所要查询的数,在当前分界点的左边时,则进行左递归,否则进行右递归。
return qs(l, j, k);
return qs(j + 1,r, k - s1);
}
int main(){
scanf("%d%d",&n,&k);
for(int i = 0; i < N; i++){
scanf("%d",&q[i]);
}
cout << qs(0,n-1,k) << endl;
return 0;
}
边栏推荐
- Postman interface test VI
- The Himalaya web version will pop up after each pause. It is recommended to download the client solution
- The method of word automatically generating directory
- [learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
- Internship log - day04
- Pit encountered by vs2015 under win7 (successful)
- Bean operation domain and life cycle
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- uboot机构简介
- ORM--数据库增删改查操作逻辑
猜你喜欢

ORM model -- creation and query of data records

ORM--数据库增删改查操作逻辑

高数_第1章空间解析几何与向量代数_向量的数量积

Postman interface test I

The landing practice of ByteDance kitex in SEMA e-commerce scene

Delete a record in the table in pl/sql by mistake, and the recovery method

Applet popup half angle mask layer

Qualifying 3

request对象对请求体,请求头参数的解析

STM32中AHB总线_APB2总线_APB1总线这些是什么
随机推荐
Guys, how can mysql-cdc convert the upsert message to append only
AI moves from perception to intelligent cognition
ISP、IAP、ICP、JTAG、SWD的编程特点
高数_第1章空间解析几何与向量代数_向量的数量积
arcgis操作:dwg数据转为shp数据
网上可以开炒股账户吗安全吗
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
Advanced function learning in ES6
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
Or in SQL, what scenarios will lead to full table scanning
[original] what is the core of programmer team management?
【ORM框架】
IPv4套接字地址结构
Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
Can I open a stock trading account online? Is it safe
LeetCode 练习——113. 路径总和 II
Deadlock caused by non clustered index in SQL Server
Postman interface test VII
