当前位置:网站首页>【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;
}
边栏推荐
- [learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- Introduction to uboot
- ORM -- database addition, deletion, modification and query operation logic
- Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
- Huffman encoded compressed file
- Guid主键
- The method of word automatically generating directory
- Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
- Why are social portals rarely provided in real estate o2o applications?
猜你喜欢

ES6中的原型对象

Postman interface test VI

STM32基础知识—内存映射

官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展

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

fiddler-AutoResponder

ISP、IAP、ICP、JTAG、SWD的编程特点

Bean operation domain and life cycle

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

The Himalaya web version will pop up after each pause. It is recommended to download the client solution
随机推荐
Guid主键
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Or in SQL, what scenarios will lead to full table scanning
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
[ORM framework]
Performance optimization record of the company's product "yunzhujia"
Memory ==c language 1
Huffman encoded compressed file
能源路由器入门必读:面向能源互联网的架构和功能
Pit encountered by vs2015 under win7 (successful)
[original] what is the core of programmer team management?
Postman interface test IV
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Delete a record in the table in pl/sql by mistake, and the recovery method
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
ORM model -- associated fields, abstract model classes
14th test
Become a "founder" and make reading a habit
