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 frkstyc at 2006-03-05 00:04:07 on Problem 2299
In Reply To:为什么是runtime error?实际运行的时候正常. Posted by:silvere at 2006-03-04 23:58:07
> 自己随便测试了几个,没有发现问题啊.
> 
> why?
> 
> 下面是source code.
> 
> thx.
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> long res=0;
> 
> void Merge(long*SR,long* TR,int i ,int m ,int n)
> {
> 	int j,k;
> 	for(j=m+1,k=i;i<=m&& j<=n;++k)
> 	{
> 		if(SR[i]<SR[j])
> 		{
> 			res+=abs(i-k);
> 			TR[k]=SR[i++];
> 		}
> 		else
> 		{
> 			res+=abs(j-k);
> 			TR[k]=SR[j++];
> 		}
> 	}
> 	if(i<=m)
> 	{
> 		for(int x=i;x<=m;x++)
> 		{
> 			res+=abs(x-k);
> 			TR[k++]=SR[x];
> 		}
> 	}
> 	if(j<=n)
> 	{
> 		for(int x=j;x<=n;x++)
> 		{
> 			res+=abs(x-k);
> 			TR[k++]=SR[x];
> 		}
> 	}
> }
> 
> void Msort(long* SR,long* TR,int s,int t)
> {
> 	int m;
> 	long dig3[500000];
> 	if(s==t)
> 		TR[s]=SR[s];
> 	else
> 	{
> 		m=(s+t)/2;
> 		Msort(SR,dig3,s,m);
> 		Msort(SR,dig3,m+1,t);
> 		Merge(dig3,TR,s,m,t);
> 	}
> }
> 
> int main()
> {
> 	int count;
> 	long dig[500000];
> 	long dig2[500000];
> 	while(scanf("%d",&count)==1)
> 	{
> 		res=0;
> 		if(count==0)
> 		{
> 			exit(0);
> 		}
> 		for(int i=0;i<count;i++)
> 		{
> 			scanf("%lld",&dig[i]);
> 		}
> 		Msort(dig,dig2,0,count-1);
> 		printf("%lld\n",res/2);
> 	}
> 	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