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

麻烦看一下,想了好多测试数据都行,一上去就WA了

Posted by Windy3721 at 2008-07-06 16:08:44 on Problem 2623
#include <iostream>
using namespace std;

unsigned long QKSort(unsigned long *array, unsigned long low, unsigned long high)
{	//实现对array的一次快速排序
 	array[0] = array[low];
	while(low < high)
	{
	    while((array[high] > array[0]) && (low < high))
		    high--;
		if(low < high)
			array[low++] = array[high];		  
		while((array[low] < array[0]) && (low <high))
		    low++;
		if(low <high)
		    array[high++] = array[low];
    } 	
	array[low] = array[0];
	return low; 
}//en of QKsort


void QuickSort(unsigned long *array, unsigned long low, unsigned long high)
{
 	if(low < high)
 	{
	 	long pos = QKSort(array,low,high);
		QuickSort(array,low,pos-1);
		QuickSort(array,pos+1,high); 	   
    }
}//end of QuickSort

int main()
{
 	long n, i=0;
	scanf("%ld",&n);
	unsigned long *sequence = new unsigned long[n+1];
	while((++i)<=n)
	    scanf("%ld",&sequence[i]);
	//end of input
	QuickSort(sequence,1,n);
	
	if(n%2 == 1)
		cout<<sequence[n/2+1]<<endl;
	else
	 	cout<<(sequence[n/2]+sequence[n/2+1])/2.0<<endl; 		
		
	system("pause");
	return 0;	 		  
}

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