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 uestc_wding01 at 2007-07-26 18:03:59 on Problem 1674
#include<stdio.h>
int a[10001];
int count;
void Quick_Sort(int left,int right)
{ 
    int tmp;
	int i,j;
	int temp;
	i=left+1;j=right;
	tmp=a[left];
       while(i<=j)
	   {
              while(a[i]<=tmp&&i<=j) i++;
              while(a[j]>=tmp&&j>=i) j--;
              if(i<j){
                     temp=a[i];
	            a[i]=a[j];
		   a[j]=temp;
	            count++;
                     i++;
                     j--;
              }
       }
	   if(left!=j)
	   {
		   a[left]=a[j];
		   a[j]=tmp;
		   count++;
	   }

       if(left<j-1) Quick_Sort(left,j-1);
       if(j+1<right) Quick_Sort(j+1,right);
}





int main()
{
	int t;
	int i;
	int n;
    int j;
    scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
		count=0;
		scanf("%d",&n);
		for(j=1;j<=n;j++)
		{
			scanf("%d",&a[j]);
		}
		Quick_Sort(1,n);
		printf("%d\n",count);
	}
	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