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 |
陷阱我避免了阿 数据测试都对的 poj是不是有问题阿代码贴上: #include<iostream> using namespace std; int cycle_length(int k); int main() { int i,j,k,temi,temj,tem,answer; cin>>i>>j; if(i>j){ temj=i; temi=j; } else { temj=j; temi=i; } //用temi,temj来计算,temi<=temj for(k=temi;k<=temj;k++){ if(k==temi)answer=cycle_length(k); else { tem=cycle_length(k); if(tem>answer)answer=tem; } } cout<<i<<" "<<j<<" "<<answer; return 0; } //-------------------------------------------------- int cycle_length(int k) { int c_l=1; while(k!=1){ if(k%2==0) k/=2; else k=(3*k+1); c_l++; } return c_l; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator