| ||||||||||
| 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 | |||||||||
方法显然有问题,结果可能很大很大~~~超出数组大小的范围In Reply To:while always runtime error,请大哥指教…… Posted by:tcx at 2005-07-18 19:57:25 > #define M1 500001
> #define M2 2000000
> #include "stdio.h"
> int main()
> { long a[M1+1],i,temp,n;
> short rec[M2+1];
> for(i=0;i<=M2;i++) rec[i]=0;
> a[0]=0; rec[0]=1;
> for(i=1;i<=M1;i++)
> { temp=a[i-1]-i;
> if (temp<=0)
> { a[i]=a[i-1]+i; rec[a[i]]=1;}
> else { if (rec[temp])
> { a[i]=a[i-1]+i; rec[a[i]]=1;}
> else { a[i]=temp; rec[temp]=1;}
> }
> }
> scanf("%ld",&n);
> while (n!=-1)
> { printf("%ld\n",a[n]);
> scanf("%ld",&n);
> }
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator