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

Runtime Error了好多次,不知道问题出在哪里?

Posted by 2008550914 at 2010-03-02 10:19:36 on Problem 2299
#include<iostream>
#define N 5000
using namespace std;

int a[N],b[N];

void MergeSort(int left,int right,__int64 &count)
{
	if(left<right)
	{
		int mid=(left+right)/2;
		MergeSort(left,mid,count);
		MergeSort(mid+1,right,count);
		int i=left,j=mid+1,k=left;
		while(i<=mid&&j<=right)
			if(a[i]<a[j]) b[k++]=a[i++];
			else 
			{
				count=count+mid-i+1;
				b[k++]=a[j++];
			}
			while(i<=mid)
				b[k++]=a[i++];
			while(j<=right)
				b[k++]=a[j++];
			for(i=left;i<=right;i++)
				a[i]=b[i];
	}
}

int main()
{
	int i,n;
	__int64 count;
	cin>>n;
	while(n)
	{
		for(i=0;i<n;i++)
			cin>>a[i];
		count=0;
		MergeSort(0,n-1,count);
        printf("%I64d\n",count);
		cin>>n;
	}
	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