当前位置:网站首页>【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;
}
边栏推荐
- Internship log - day04
- ORM -- database addition, deletion, modification and query operation logic
- Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
- 字节跳动 Kitex 在森马电商场景的落地实践
- Deadlock caused by non clustered index in SQL Server
- 大整数类实现阶乘
- ES6中的函數進階學習
- 每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
- ISP、IAP、ICP、JTAG、SWD的编程特点
- STM32中AHB总线_APB2总线_APB1总线这些是什么
猜你喜欢

Pit encountered by vs2015 under win7 (successful)

Postman interface test I

XML配置文件解析与建模

Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat

柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?

ORM -- database addition, deletion, modification and query operation logic

【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)

Enterprise practice | construction of banking operation and maintenance index system under complex business relations

AI moves from perception to intelligent cognition

ORM--数据库增删改查操作逻辑
随机推荐
The request object parses the request body and request header parameters
Huffman encoded compressed file
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Postman interface test III
Methods of adding centerlines and centerlines in SolidWorks drawings
Why are social portals rarely provided in real estate o2o applications?
Or in SQL, what scenarios will lead to full table scanning
ISP、IAP、ICP、JTAG、SWD的编程特点
Guid主键
Some test points about coupon test
Web3.0 series distributed storage IPFs
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
MongoDB创建一个隐式数据库用作练习
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
CONDA creates virtual environment offline
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
IPv4套接字地址结构
Luogu p2482 [sdoi2010] zhuguosha
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
