Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
局部变量与全局变量有何差别#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator