Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我自己写了个快排,AC了它,哈哈,再也不想用algorithm

Posted by gfedcba at 2009-03-04 14:13:10 on Problem 3627
In Reply To:破题,还以为是最多能装多少,6+11+11=28<40,结果又看一遍题就AC了。 Posted by:julyflame at 2009-03-04 13:06:39
void Qsort(int low, int high)
{
	if (low >= high)
	{
		return ;
	}
	int l, mid, r, pivot;
    //mid = low +(high-low)>>1; // + -的优先级比>>还大,又一次在这里翻船了!!!!
	mid = low + (high-low>>1); 
	Swap(arr[mid], arr[high]);

	l = low, r = high-1;
	while (l<=r)
	{
		while (l<=r && arr[l] <= arr[high])
		{
			l++;
		}
		while (l<=r && arr[r] >= arr[high])
		{
			r--;
		}

		if (l<=r)
		{
			Swap(arr[l], arr[r]);
			l++;
			r--;
		}

		if (l>r)
		{
			pivot = l;
			break;
		}
	}

	Swap(arr[pivot], arr[high]);
	Qsort(low, pivot-1);
	Qsort(pivot+1, high);


}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator