2012-06-0822:26:07题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=271
/*
/* #include<stdio.h> #include<string.h> int visit[10000]; int fun(int a,int b,int i) { int num=1; while(i!=1) { if(i&1) { i=3*i+1; if(i<=b&&i>=a) visit[i]=1; } else { i>>=1; if(i<=b&&i>=a) visit[i]=1; } ++num; } return num; } int main() { int a,b,i,flag,t,ans,temp; while(scanf("%d%d",&a,&b)!=EOF) { memset(visit,0,sizeof(10000)); ans=1; flag=0; if(a>b) { flag=1; t=a; a=b; b=t; } for(i=a;i<=b;++i) if(!visit[i]) { temp=fun(a,b,i); if(temp>ans) ans=temp; } if(flag) printf("%d %d %d\n",b,a,ans); else printf("%d %d %d\n",a,b,ans); } return 0; }//超时 */ #include <iostream> using namespace std; int d[10003]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout);//会自动生成 int i,j,t; for(int k=2;k<10003;k++)//打表 { t=k; while(1!=t) { if(t&1) { t=t*3+1; } else t>>=1; d[k]++; } } while(cin>>i>>j) { int max=0,t=0; cout<<i<<" "<<j<<" "; if(i>j)//交换i和j的值 { i^=j;j^=i;i^=j; } for(int k=i;k<=j;k++) { if(max<d[k]) max=d[k]; } cout<<max+1<<endl; } return 0; }