先上代码:
#include <iostream>
using namespace std;
int n, k, a[10010] = {};
int main(){
cin >> n >> k;
for(int i = 0; i < n; i++){
int x;
cin >> x;
a[x]++;
}
int m = 0;
for(int i = 0; i < n; i++){
if(a[i] != 0){
m++;
}
if(m == k){
cout << i;
return 0;
}
}
cout << "NO RESULT";
return 0;
}
想问一下这题桶排可不可行?
我的思路是,
把相同的装进一个桶,最后以m==k,
即桶名与k相同时输出i得出第k小的数,
请dalao们指出错误,蟹蟹:)