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 纪念一下!!! 哈哈~~~ 代码贴上

Posted by 937207021 at 2011-07-25 20:23:18 on Problem 2388
第一次 一次就ac 纪念一下!!!  哈哈~~~  代码贴上


#include<stdio.h>
#define N 100000
typedef int type;
int partition(type *tt,int low,int high);
void Qsort(type *tt,int low,int high);
int main()
{
	int n,i,tt[N];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&tt[i]);
	Qsort(tt,0,n-1);
	printf("%d\n",tt[(n-1)/2]);
	return 0;
	
}
int partition(type *tt,int low,int high)
{  
	type pivotkey;
	pivotkey=tt[low];
	while(low<high)
	{
		while(low<high && tt[high]>=pivotkey) high--;
		tt[low]=tt[high];
		while(low<high && tt[low]<=pivotkey) low++;
		tt[high]=tt[low];
	}
	tt[low]=pivotkey;
	return low;
}
void Qsort(type *tt,int low,int high)
{
	int pivot;
	if(low<high)
	{
		pivot=partition(tt,low,high);
		Qsort(tt,low,pivot-1);
		Qsort(tt,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