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 ActionNow at 2009-08-21 16:45:16 on Problem 2460
#include <stdio.h>
int x[200002],y[200002];
main()
{
	int i,j,n,m,X,Y,scst,scol;
	scanf("%d",&n);
	while(n)
	{
		scst=0;
		scol=0;
		for(i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
		X=x[(1+n)/2];
		Y=y[(1+n)/2];
		for(i=1;i<=n;i++)
		{
			if(x[i]>X&&y[i]>Y||x[i]<X&&y[i]<Y)
			scst++;
			else if(x[i]>X&&y[i]<Y||x[i]<X&&y[i]>Y)
			scol++;
		}
		printf("%d %d\n",scst,scol);
		scanf("%d",&n);
	}
}
这是我这一题的代码,将x[]和y[]申请为全局变量时内存是184K,时间是0Ms。
可是当把x[]和y[]申请为局部变量时内存就变成了1720K,时间也变成了16Ms。这是为什么?哪位帮忙解释一下!

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