RE+WA的保龄,求助qwq

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

SIXIANG32 @ 2020-03-30 10:03:07

#include<iostream>
using namespace std;
bool flag[100000000];
int a;
int main()
{
    int n,k,y=-1,min=100000000,max=0;
    cin>>n>>k;
    for(int p=1;p<=n;p++)
    {
        cin>>a;
        flag[a]=0;
        if(a<min)min=a;
        if(a>max)max=a;
    }
    for(int p=min;p<=n;p++)
    {
        if(flag[p]==0)
        y++;
        if(y==k)
        {
            cout<<p<<endl;
            return 0;
        }
    }
}

救救我吧qwqqAq


by cqazy811 @ 2020-03-30 10:04:06

思路有问题,自己参考题解思路


by SIXIANG32 @ 2020-03-30 10:05:09

@虚空者 我不想宗明


by liqingyang @ 2020-03-30 10:05:41

@SIXIANG 参考


by cqazy811 @ 2020-03-30 10:06:33

@SIXIANG 参考思路是没错的,不要照着打/抄袭就行惹w


by liqingyang @ 2020-03-30 10:06:33

@SIXIANG 算了,我一会看看吧


by SIXIANG32 @ 2020-03-30 10:06:48

@liqingyang STL?


by dingcx @ 2020-03-30 10:07:28

排序它不香吗


by tangrunxi @ 2020-03-30 10:08:38

sort好像TLE了


by liqingyang @ 2020-03-30 10:10:15

@tangrunxi 真的吗?


by tangrunxi @ 2020-03-30 10:11:20

@liqingyang 是的,具体看这里


| 下一页