晴天娃娃rt @ 2021-01-17 14:11:15
求求谁能帮我看看代码啊,后两个点TLE了
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[10000000];
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+1+n);
cout<<a[k+1];
return 0;
}
by CGDGAD @ 2021-01-17 14:13:16
因为本题的重点在于练习分治算法。
您分治了吗
by _Empty @ 2021-01-17 14:15:09
@晴天娃娃rt
sort 改成 nth_element
by HYdroKomide @ 2021-01-17 14:25:56
不要使用nth_element,我们要练习分治算法!
by Durancer @ 2021-01-17 14:46:16
inline int read() {
int s = 0, f = 1; char ch = gc;
for(; ch < '0' || ch > '9'; ch = gc) if(ch == '-') f = - 1;
for(; ch >= '0' && ch <= '9'; ch = gc) s = (s << 3) + (s << 1) + (ch ^ 48);
return s * f;
}
快读大法好!
by 晴天娃娃rt @ 2021-01-17 16:13:03
谢谢
by dinglinxi0409 @ 2021-02-07 17:55:29
或者开启O2优化 顺便附上我的AC记录