Help!!

P1923 【深基9.例4】求第 k 小的数

soywcy @ 2020-05-10 17:28:51

超级蒟蒻我又来了。。。

#include<bits/stdc++.h>
#define f(i,j,n) for(int i=j;i<=n;i++)
#define _f(i,j,n) for(int i=n;i>=j;i--)
using namespace std;
typedef long long ll;
inline int read(){
    int X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
    if(flag) return X;
    return ~(X-1);
}
inline int write(int X)
{
    if(X<0) {putchar('-'); X=~(X-1);}
    int s[20],top=0;
    while(X) {s[++top]=X%10; X/=10;}
    if(!top) s[++top]=0;
    while(top) putchar(s[top--]+'0');
}
int n,k,a[1000010];
int main(){
    ios::sync_with_stdio(0);
    n=read(),k=read();
    f(i,1,n) a[i]=read();
    sort(a+1,a+n+1);
    write(a[k]);
    return 0;
}

本想快读sort+O2水过去的

结果。。。

三色死亡现场


by cvyl30 @ 2020-05-10 17:30:05

n<5000000


by zhangyiheng2006 @ 2020-05-10 17:30:09

数组小了


by asasas @ 2020-05-10 17:31:14

@48K纯金WA 大哥你每次数组都开小了,注意数据范围


by W_churchill @ 2020-05-10 17:31:30

要用register定义+scanf输入+printf输出+O2才能过去。。。


by W_churchill @ 2020-05-10 17:32:02

话说你怎么又来了


by W_churchill @ 2020-05-10 17:32:15

还是同一个问题


by W_churchill @ 2020-05-10 17:32:33

其实不用快读


by W_churchill @ 2020-05-10 17:33:05

#include<bits/stdc++.h>
using namespace std;
int a[5000010];
int main()
{
    register int n,k;
    scanf("%d%d",&n,&k);    
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    printf("%d",a[k]);
    return 0;
}

这是我的代码,给您参考一下


by soywcy @ 2020-05-10 17:38:29

谢谢各位,这下长记性了


by ⚡zhangjingcan⚡ @ 2020-05-10 17:51:33

@Qinclude register没用


|