刷题记录:牛客NC207028第k小数

传送门:牛客

题目描述:

给你一个长度为n的序列,求序列中第k小数的多少。
输入:
2
5 2
1 4 2 3 4
3 3
3 2 1
输出:
2
3

emmm,是一道典型的排序题,快排,归并排序,桶排什么的应该都可以,但是作为c++选手,当然是选择使用sort来直接偷懒了,一行的事复杂度又那么的优秀,何乐而不为呢??

注意使用快读(毕竟题目提醒了,当然一直使用快读也是一个好习惯哦)

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {
	ll x=0,w=1;char ch=getchar();
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*w;
}
#define maxn 1000000
int a[5000003];
int main() {
	int T;T=read();
	while(T--) {
		memset(a,0,sizeof(a));
		int n,k;n=read();k=read();
		for(int i=1;i<=n;i++) a[i]=read();
		sort(a+1,a+n+1);
		printf("%d\n",a[k]);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值