zzzzzzq @ 2023-09-20 20:17:02
#include <string.h>
#define ll long long
using namespace std;
int n; //n up to 500,0000; and n is a 奇数;
int k;
int arr[5000000];
void quicksort
(int arr[], int l, int r)
{
if (l >= r) return;
int i = l, j = r, x = arr[(l + r) >> 1];
while (i < j) {
while (arr[i] < x) i++;
while (arr[j] > x) j--;
if (i < j)
{
swap(arr[i], arr[j]);
i++;
j--;
}
}
if (k <= j)
quicksort(arr, l, j);
else if (k > i)
quicksort(arr, i, r);
else
{
cout << arr[i] << endl;
return;
}
}
int main()
{
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> arr[i];
quicksort(arr, 0, n - 1);
return 0;
}
by 2011__SJY @ 2023-09-20 20:28:20
#include<bits/stdc++.h>
using namespace std;
int arr[5000005],k;
int main(){
int n;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
nth_element(arr+0,arr+k,arr+n);
printf("%d",arr[k]);
return 0;
}
@zzzzzzq 这个可以,是题解我直接去厕所里**
by zzzzzzq @ 2023-09-20 20:30:25
@2011__SJY
不是很想用STL哈哈哈哈,不过还是很感谢!!!
by Hauauah @ 2024-01-22 01:53:01
TMD为啥不对,我也是一样的
by Hauauah @ 2024-01-22 01:53:29
@Hauauah 今晚睡不着觉了