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 |
暴力能过,时间只要0ms,内存为284K#include<iostream> using namespace std; int array[10008]={0}; int f(int n) { if(n%2==0) return f(n/2)+1; if(n%2!=0&&n>1) return f(3*n+1)+1; if(n==1) return 1; } int main() { int i,a,b,m,n; for(i=1;i<=10000;i++) array[i]=f(i); while(cin>>m>>n) { a=m<n?m:n; b=m>n?m:n; int max=0; for(i=a;i<=b;i++) if(array[i]>max) max=array[i]; cout<<m<<" "<<n<<" "<<max<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator