wumingwei @ 2021-09-18 22:18:46
超时求解
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5000000],b,c;
cin>>b>>c;
for(int i=0;i<b;i++)
{
cin>>a[i];
}
nth_element(a,a+c,a+b);
cout<<a[c];
return 0;
}
by S0CRiA @ 2021-09-18 22:19:55
别用cin
by wumingwei @ 2021-09-18 22:20:25
@Fее_cle6418 拿用什么
by Need_No_Name @ 2021-09-18 22:21:47
@wumingwei
#include<bits/stdc++.h>
# define int long long
using namespace std;
int a[5000001],b,c;
signed main()
{
ios :: sync_with_stdio(false);
cin>>b>>c;
for(int i=0;i<b;i++)
{
cin>>a[i];
}
nth_element(a,a+c,a+b);
cout<<a[c];
return 0;
}
还是得卡一下的。。。
by Need_No_Name @ 2021-09-18 22:22:11
@wumingwei 快读或scanf都可以的
by Eroded @ 2021-09-18 22:22:18
@wumingwei 加个ios::sync_with_stdio(false);
by wumingwei @ 2021-09-18 22:23:00
@Need_No_Name 有差别吗
by Need_No_Name @ 2021-09-18 22:24:07
@wumingwei 当然有啊,好好观察
多了一个“ios :: sync_with_stdio(false);”,数组变量定义也最好放在了main函数的上面
by 红尘仙 @ 2021-09-18 22:24:23
@wumingwei 换快读也可以
int read() {
int x = 0 , f = 1 ; char ch = getchar() ;
while(!isdigit(ch)) {if(ch == '-') f = - 1 ; ch = getchar() ;}
while( isdigit(ch)) {x = x * 10 + ch - '0' ; ch = getchar() ;}
return x * f ;
}
by Need_No_Name @ 2021-09-18 22:24:50
@wumingwei 主要是输入上的优化。。。当然用scanf和快读也是可以的
by songxiao @ 2021-09-18 22:24:54
@wumingwei 输入输出会更快