AIMEE11 @ 2022-11-07 22:37:19
#include<iostream>
using namespace std;
const int N=500000;
int main()
{
int n,a[N],k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
if(a[i]>a[j])
{
int t=a[j];
a[i]=a[j];
a[j]=t;
}
for(int i=1;i<=n;i++)
if((k+1)==i) cout<<a[i];
return 0;
}
by jjx11 @ 2022-11-07 22:39:54
有没有一种可能性,是这道题的算法不是冒泡?复杂度明显超时。
by 1179083629dsm @ 2022-11-07 22:40:56
sort或快速选择
by LuminaryWay @ 2022-11-08 07:28:38
直接用sort函数
by Vanishing_Stars @ 2022-11-08 08:23:38
@AIMEE11 题目说
输入
n (1 \le n < 5000000 且n 为奇数)个数字
所以你的常量
by Vanishing_Stars @ 2022-11-08 08:52:07
@AIMEE11 另外一提,这题用
by Vanishing_Stars @ 2022-11-08 08:59:13
@AIMEE11 我终于
by AIMEE11 @ 2022-11-08 12:36:08
@Vanishing_Stars 谢谢鸟
by 心灵震荡 @ 2022-11-11 11:01:56
哇,黄题还有手打冒泡的勇士吗?
by AIMEE11 @ 2022-11-11 13:22:41
@busy_programmer 我可以说我懒得用sort吗?((
by AIMEE11 @ 2022-11-11 13:49:22
上面发的那句划掉 (