?

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

4041nofoundGeoge @ 2024-04-18 20:36:20

#include <bits/stdc++.h>
using namespace std;
int a[5000005]={};
int main()
{
    int n,k;
    cin>>n>>k;
    k+=1;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    int cnt=0;
    for(int i=1;;i++)
    {
        if(a[i]!=a[i-1])cnt++;
        if(cnt==k)
        {
            cout<<a[i]<<endl;
            return 0;
        }
    }
    return 0;
}

by Carey_chen @ 2024-04-18 20:48:05

#include <bits/stdc++.h>
using namespace std;
int a[5000005];//预处理文件过大,会CE
int main()
{
    int n,k;
    cin>>n>>k;
    k+=1;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    printf("%d", a[k]);//排序之后直接输出即可
    return 0;
}

by fish_love_cat @ 2024-04-18 20:48:09

?


by GoodLuckCat @ 2024-04-18 20:48:29


by cj180202 @ 2024-04-18 20:55:43

?


by XuYueming @ 2024-04-18 21:00:19


by 4041nofoundGeoge @ 2024-04-18 22:26:37

?有tle


by Samuume @ 2024-04-26 17:10:33

scanf(doge)


by WZwangchongming @ 2024-05-02 14:53:53

?


by 4041nofoundGeoge @ 2024-05-02 19:53:41

?


|