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 |
内存是不是有点问题?我开这么大的内存,结果过了,还只用2M. Memory: 2624K Time: 0MS Language: C++ Result: Accepted #include "stdio.h" int len[50000001]; int f(int v); int main(int argc, char* argv[]) { int a,b; while(scanf("%d %d",&a,&b)!=EOF) { int x=a<b?a:b; int y=a>b?a:b; int maxlen=f(x),i; for(i=x+1;i<=y;++i) if(maxlen<f(i)) maxlen=f(i); printf("%d %d %d\n",a,b,maxlen); } return 0; } int f(int v) { if(len[v]) return len[v]; if(v==1) len[v]=1; else if(v%2) len[v]=f(v*3+1)+1; else len[v]=f(v/2)+1; return len[v]; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator