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:Why Time Limit Exceed?(C++) Posted by:shiming413 at 2005-10-23 23:42:28 > 代码如下: > #include <stdio.h> > int a[1000]={1,0}; > int main() > { > int n,i,j,c; > while(scanf("%d",&n)!=EOF) > { > a[0]=1; > for(i=1;i<1000;i++) > a[i]=0; > if(n==1) > { > printf("0\n"); > continue; > } > if(n==2||n==3) > { > printf("1\n"); > continue; > } > for(i=0;i<n-3;i++) > { > c=0;j=0; > do > { > c+=2*a[j]; > a[j]=c%10; > c/=10; > j++; > }while(c!=0||j<n); > if(i%2==0) > { > c=1;j=0; > do > { > c+=a[j]; > a[j]=c%10; > c/=10; > j++; > }while(c!=0); > } > else > { > c=-1;j=0; > do > { > c+=a[j]; > a[j]=c%10; > c/=10; > j++; > }while(c!=0); > } > } > if(i%2==2) > { > c=1;j=0; > do > { > c+=a[j]; > a[j]=c%10; > c/=10; > j++; > }while(c!=0); > } > i=999; > while(a[i]==0) > i--; > for(;i>=0;i--) > printf("%d",a[i]); > putchar('\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