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

问一下为什么run time error?

Posted by dynaturtle at 2006-08-13 00:11:01 on Problem 2299
以下是source code

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STR_LENGTH 500000
#define DATA_LENGTH 100

_int64 Get_Measure(int* Seqs,int head,int tail);

int main()
{
	int Seqs[STR_LENGTH];

	//Get the Seqs
	int number;
	
	int counter;
	_int64 result;	

	cin>>number;
	while (number!=0)
	{
		for(counter=0;counter<number;counter++)
		{
			cin>>Seqs[counter];	
		}
	
		result=Get_Measure(Seqs,0,number-1);	

		scanf("%I64\n",&result);

		cin>>number;
	}


	return 0;
}

_int64 Get_Measure(int* Seqs,int head,int tail)
{	
	if (head==tail)
		return 0;

	_int64 sum=0;
	int length;
	int* array;

	array=(int*)malloc(sizeof(int)*(tail-head+1));
	sum=Get_Measure(Seqs,head,(head+tail)/2)+Get_Measure(Seqs,(head+tail)/2+1,tail);
	length=(head+tail)/2-head+1;

	int i,tag1=head,tag2=(head+tail)/2+1;

	for(i=0;i<tail-head+1;i++)
	{
		if (Seqs[tag1]<Seqs[tag2])
		{
			array[i]=Seqs[tag1];
			tag1++;
			length--;
		}
		else 
		{
			array[i]=Seqs[tag2];
			tag2++;
			sum+=length;
		}
	}
	
	for(i=0;i<tail-head+1;i++)
		Seqs[head+i]=array[i];
	free(array);

	return sum;
}

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