(以“分类:递归 ==摘要== {{信息题|3n+1问题|http://www.codevs.cn/problem/3038/|1|100|time=2014-10-11 12:26:43}} ==题意== 给出递推式,求求解步数...”为内容创建页面) |
小 (错误原因补充) |
||
| 第1行: | 第1行: | ||
[[分类:递归]] | [[分类:递归]] | ||
==摘要== | ==摘要== | ||
| − | {{信息题|3n+1问题|http://www.codevs.cn/problem/3038/|1|100|time=2014-10-11 12:26:43}} | + | {{信息题|3n+1问题|http://www.codevs.cn/problem/3038/|1|100|输出格式|0|time=2014-10-11 12:26:43}} |
==题意== | ==题意== | ||
给出递推式,求求解步数。 | 给出递推式,求求解步数。 | ||
| 题目链接 | 难度等级 | 完成状态 | 完成分数 | 最后编辑时间 | 失误原因(初次提交分数) |
|---|---|---|---|---|---|
| 3n+1问题 | ★☆☆☆☆ | 答案正确 | 100 | 2014-10-11 12:26:43 | 输出格式(0) |
给出递推式,求求解步数。
简单递归。
| 3038.cpp代码已折叠
展开折叠内容
|
|---|
#include<iostream>
const int f(const int &n,const int &step)
{
if(n==1)
return step;
return (n%2)?f(3*n+1,step+1):f(n>>1,step+1);
}
int main()
{
int n,x;
std::cin>>n;
while(n--)
{
std::cin>>x;
std::cout<<f(x,0)<<std::endl;
}
return 0;
}
|