re?

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

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 Eason_AC @ 2021-09-15 22:26:37

@wumingwei 数组要开到 5\times 10^6,你只开到了 10^4


by int32 @ 2021-09-15 22:26:53

1≤n<5000000


by Need_No_Name @ 2021-09-15 22:28:44

@wumingwei 小心TLE


by wumingwei @ 2021-09-15 22:29:34

@Eason_AC 还有两个4和5没过啊


by 8ec0c7 @ 2021-09-15 22:30:02

@wumingwei 而且您的 cmp 似乎白写了(如果不是当我没说


by Eason_AC @ 2021-09-15 22:30:23

@wumingwei sort 复杂度 \mathcal O(n\log n) 过不了的,建议用二分


by wumingwei @ 2021-09-15 22:31:17

江湖求解 最后两个没过


by Need_No_Name @ 2021-09-15 22:32:58

@wumingwei 时间复杂度不对啊


by Need_No_Name @ 2021-09-15 22:33:30

@wumingwei O(nlogn) 绝对T飞


by wumingwei @ 2021-09-15 22:33:37

@Eason_AC 排序没拍好怎么2分,冒泡?


| 下一页