BugManMax @ 2024-04-18 16:59:34
#include<bits/stdc++.h>
using namespace std;
int x[5000005],k;
void fenzhi(int l,int r)
{
int i=l;
int j=r;
int m=x[(l+r)/2];
//int m = (l+r)/2
do
{
//while(x[j]>x[m])
while(x[j]>m)
j--;
//while(x[i]<x[m])
while(x[i]<m)
i++;
if(i<=j)
{
swap(x[i],x[j]);
i++;
j--;
}
}
while(i<=j);
if(k<=j)
fenzhi(l,j);
else if(i<=k)
fenzhi(i,r);
else
cout<<x[k];
}
int main()
{
ios::sync_with_stdio(0);
int n;
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>x[i];
fenzhi(0,n-1);
}
by kevinZ99 @ 2024-04-18 17:24:14
@BugManMax 因为 swap(a[i],a[j])
换掉了啊