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 |
解题思路我用个递归打表 然后再搜索MAX就搞定了,用时15MS 先把2的幂次的次数保存起来, for(i=1;i*2<=100000;i=i*2) { result[i*2]=result[i]+1; } 再打表 int get_step(int *r,int n) { int step=1; if(n%2) { n=n*3+1; while(n>100000) { step++; if(n%2)n=n*3+1; else n=n/2; } if(r[n])return step+r[n]; else return step+get_step(r,n); } else { n=n/2; if(r[n])return step+r[n]; else return step+get_step(r,n); } }; 有更好的算法请大牛发我邮箱,大家讨论一下呵呵 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator