wumingwei @ 2021-09-15 22:25:34
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a<b;
}
int main()
{
int a[10000],b,c;
cin>>b>>c;
for(int i=0;i<b;i++)
{
cin>>a[i];
}
sort(a,a+b,cmp);
cout<<a[c];
return 0;
}
这个为什么是RE,亲自测没有问题啊!
by Need_No_Name @ 2021-09-15 22:34:03
@wumingwei 用
nth_element
试试
by Need_No_Name @ 2021-09-15 22:35:04
@wumingwei 冒泡
by wumingwei @ 2021-09-15 22:35:16
@Need_No_Name 这是什么 教教我
by 8ec0c7 @ 2021-09-15 22:36:22
@wumingwei 第一篇题解,请
by Need_No_Name @ 2021-09-15 22:37:00
@wumingwei nth_element(数组名,数组名+第k小元素,数组名+元素个数)
直接
by qwq___qaq @ 2021-09-15 22:48:28
@Eason_AC 不,可以过:
#include<bits/stdc++.h>
using namespace std;
int n,k,a[5000000];
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
printf("%d\n",a[k]);
return 0;
}
by qwq___qaq @ 2021-09-15 22:49:56
@Eason_AC
by qwq___qaq @ 2021-09-15 22:50:53
@Eason_AC 当然只要你懂得吸氧。
by Onana_in_XMFLS @ 2021-09-15 23:00:20
@wumingwei 这题吸氧纯排序可过,话说这还是我写的第一题黄题