怎么优化啊???

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

W_churchill @ 2020-03-31 22:44:23

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

为什么3A2TLE


by W_churchill @ 2020-04-01 18:39:39

https://www.luogu.com.cn/record/32377651 为什么还是60分QWQ


by 唱个歌 @ 2020-04-18 15:44:23

@Qinclude 大哥他叫你for循环里面用scanf,话说你写的题也太多了把


by W_churchill @ 2020-04-19 10:37:15

@唱个歌 emmmm,怎么突然有人回我了


by 唱个歌 @ 2020-04-19 10:41:21

@Qinclude emm,话说你是高中生吗


by W_churchill @ 2020-04-19 10:45:13

@唱个歌 小学生


by W_churchill @ 2020-04-19 10:46:19

@唱个歌 怎么停止工作了?话说没用错吧?

#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 唱个歌 @ 2020-04-19 10:59:58

@Qinclude

太强了,

scanf("%d",&a[i]);

要加一个取地址符


by W_churchill @ 2020-04-19 11:07:17

@唱个歌 好吧我承认我只学过C++


by W_churchill @ 2020-04-19 11:07:56

#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;
}

可是还是TLE,这题也太毒瘤了吧


by 唱个歌 @ 2020-04-19 11:14:27

@Qinclude 你提交代码时开 开启 O2 优化了吗


上一页 | 下一页