转载自:http://www.clumsyfool.com/index.php/archives/450
Ps:一开始没搞懂输入数据是什么意思,此题输
入两个数,求出从i-j中通过所给算法得到的数串
中最多的那个数串的个数。遍历i-j。
解题报告:
此水题浪费了很长时间,主要是解此题需要多个变量分别代表不同含义,
做题的时候变量一定要定好,不能混淆。!
题目地址 <http://acm.hdu.edu.cn/showproblem.php?pid=1032>
#include <iostream>
using namespace std;
int main()
{
int i,j,n,m,len,max,c,b;
int k;
while(cin>>i>>j)
{
n=i;m=j;
if(i>j) {k=i;i=j;j=k;}
max=1;
for(b=i;b<=j;b++)
{
c=b;
len=1;
while(c!=1)
{
if(c%2==0)
{
c=c/2;
}
else
{
c=c*3+1;
}
len++;
}
if(max<len)
max=len;
}
cout<<n<<' '<<m<<' '<<max<<endl;
}
return 0;
}