ziqikang @ 2024-10-19 21:05:39
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int n,k;
//
void wwqsort(int arr[],int l,int r)
{
if (l >= r) return;
int mid = (l + r) / 2;
swap(arr[l],arr[mid]);
int i = l + 1,j = r;
while (i <= j)
{
while (i <= j && arr[i] < arr[l]) i++;
while (i <= j && arr[j] > arr[l]) j--;
if (i <= j)
{
swap (arr[i],arr[j]);
i++,j--;
}
}
swap(arr[l],arr[j]);
wwqsort(arr,l,j - 1);
wwqsort(arr,j + 1,r);
}
int main()
{
cin >> n >> k;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
}
wwqsort(a,1,n);
cout << a[k];
return 0;
}
by lihl @ 2024-10-19 21:12:32
你得查找过程中输出而不是sort后输出,这样和直接sort没区别
by kevin110609 @ 2024-10-19 21:15:57
sort复杂度O(nlogn),题目数据过不了
by kevin110609 @ 2024-10-19 21:16:39
建议使用sort二分法或nth_element解决
by kevin110609 @ 2024-10-19 21:18:15
并且建议使用快读,因为本题数据量较大
by wanghaorui2012 @ 2024-10-19 22:14:53