题目描述
请问一下这里的基准为什么不可以选中间数??????
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int halfquicksort(int q[],int low,int high,int k){
int x = q[low],l = low,r = high;
while(low < high){
while(low < high&&q[high] >= x)high--;
q[low] = q[high];
while(low < high&&q[low] <= x)low++;
q[high] = q[low];
}
q[low] = x;
//cout << l << endl;
if(low == k)return q[low];
else if(low > k)return halfquicksort(q,l,low-1,k);
else return halfquicksort(q,low+1,r,k);
}
int main()
{
int n,k;
int a[N];
scanf("%d%d",&n,&k);
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
}
cout << halfquicksort(a,1,n,k);
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla