**
航电oj:The 3n + 1 problem
**
#题目描述
#给你许多数,两两一对,让你求在这两数之间的所有数中(包括两端)运行提供函数循环循环次数的最大值
#还以为要用动规,但是想不出来,就暴力算了,结果能过 (⊙﹏⊙)
#知识点
递归?
#代码
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,temp,math1,math2;
int answer[10020];
int three_n(int i)//递归就嗯算
{
if(i==1)
return 1;
if(i%2==0)
return (three_n(i/2)+1);
else
return (three_n(3*i+1)+1);
}
int main()
{
memset(answer,0,sizeof(answer));
answer[1]=1;
int max = -20000;
while(scanf("%d%d",&n,&m)!=EOF)
{
max = -20000;
math1 = n;
math2 = m;
if(n>m)//还是怕被坑 就加了调换 所有要保障原始数据 用math系列存住
{
temp = n;
n = m;
m = temp;
}
for(int i=n;i<=m;i++)
{
temp = three_n(i);
if(temp > max)
max = temp;
}
printf("%d %d %d\n",math1,math2,max);
}
return 0;
}
#总结
要多练练递归 这个写的有点慢了 想了好久 思维紊乱了