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

SIMPLE 都过了,为啥WA啊,请大牛帮忙看一下

Posted by 666999 at 2009-05-10 23:37:58 on Problem 2299
#include<iostream>
using namespace std;
long long a[500000],c[500000];
long long MergeSort(long long a[],long long c[],int left,int right)
{
	int i,j,mid,temp,count;
	long long   total=0;
	if(left>right)
	return 0;
		mid=(left+right)/2;
		count=0;
		i=left;
		j=mid+1;
		while(i<=mid && j<=right)
		{
			if (a[i]>a[j]) 
            {
				total+=mid-i+1;//从右表移出一个元素,同时 total 累加左表此时的元素个数 
				c[count++]=a[j++];
			} 
			else 
            {
				c[count++]=a[i++];
			}
	   }
	return total;
}
int main()
{
	int n,i,j;
	long long  total;
	while (1)
	{   scanf("%d",&n);
	   if(n==0)
	   break;
		for (i=0;i<n;i++)
		{
        scanf("%lld",&a[i]);
        }
		total=MergeSort(a,c,0,n-1);
		printf("%lld\n",total);
	}
       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