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

好伤心,连个快排找数都写不出来~

Posted by SCNUlittle at 2010-11-09 18:56:07 on Problem 2388 and last updated at 2010-11-09 18:58:13
include<iostream>
using namespace std;
	int n;
	int a[10000]={0};
int qsort(int c,int b,int m)
{
	int i=c,j=b;
	if(i==j)return a[i];
	int mid=a[(i+j)>>1];
	while(i<j)
	{
		while(a[i]<mid)i++;
		while(a[j]>mid)j--;
		if(i<=j)
		{
			swap(a[i],a[j]);
			i++;
			j--;
		}
	}
	if((i+j)/2==m)return a[m];
	else
	{
		if(i<m)qsort(i,b,m);
		if(j>m)qsort(c,j,m);
	}
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		int t=qsort(0,n-1,(n-1)/2);
		printf("%d",t);

	}
}
怎么错的啊

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