poj1207(3n+1)
来源:互联网 发布:amd是什么软件 编辑:程序博客网 时间:2024/05/17 03:34
题意: 3n+1问题,如果i为奇数,则执行i=i*3+1; 否则i/=2; 开始的时候根本就没想到这个题会卡住。错了n遍后,终于鼓起勇气百度了一下,才知道,需要考虑n,m的大小。
<pre name="code" class="html">#include<iostream> using namespace std;int main() { int m, n, i, cnt, t; int max; while(cin>>n>>m) { cout<<n<<" "<<m<<" "; if(n>m){ t = n; n = m; m = t; } max = -1; for(i=n; i<=m; i++) { cnt = 1; t = i; while(t-1) { cnt++; if(t%2) t = 3*t+1; else t = t/2; } if(max<cnt) max = cnt; } cout<<max<<endl; } return 0; }
0 0
- poj1207(3n+1)
- poj1207(The 3n + 1 problem)
- poj1207-the 3n+1 problems
- poj1207--The 3n + 1 problem
- 【模拟】poj1207 The 3n + 1 problem
- POJ1207 The 3n + 1 problem
- poj1207 The 3n + 1 problem
- poj1207-The 3n + 1 problem
- poj1207 The 3n + 1 problem
- 北大暑假训练计划—POJ1207 The 3n + 1 problem(C语言)
- poj1207——The 3n + 1 problem
- POJ1207,The 3n + 1 problem,水输出要注意...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
- POJ1207
- poj1207
- poj1207
- POJ1207
- POJ1207
- LeetCode -- Surrounded Regions
- 数据结构 第一章 绪论 思维导图
- 第一篇文章
- 6661 Equal Sum Sets(DP)
- lightoj 1024 Eid
- poj1207(3n+1)
- 构造函数
- C/C++函数调用过程分析
- SQL Get the primary key name/ drop pk/ add pk
- UVA 12171 Sculpture 离散化 floodfil 立方体体积并 转换
- C++函数调用过程深入分析
- LeetCode: Balanced Binary Tree
- EL表达式中的11个隐式对象
- about git-merge "Binary files differ"