P1923 后两个点超时 请帮我看看代码的问题
查看原帖
P1923 后两个点超时 请帮我看看代码的问题
1065928
XiaoYuyu楼主2023/10/31 11:56
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int n, ans,k;
int partition(int a[], int low, int high)
{
	int pivot = a[low];
	while (low < high)
	{
		while (low < high && a[high] >= pivot)
			high--;
		a[low] = a[high];
		while (low < high && a[low] <= pivot)
			low++;
		a[high] = a[low];
	}
	a[low] = pivot;
	return low;

}
int quicksort(int a[], int low, int high)
{
	if (low < high)
	{
		int pivot = partition(a, low, high);
		if (k == pivot)
		{
			return pivot;
		}
		if (k <= pivot)
		quicksort(a, low, pivot - 1);
		if(k>= pivot)
		quicksort(a, pivot + 1, high);
	}

}

int main()
{
	int  a[5000005]={0};
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	quicksort(a, 0, n-1);
	cout << a[k] << endl;
	
}

请求帮我debug

2023/10/31 11:56
加载中...