HDOJ 1032 The 3n + 1 problem(水)
来源:互联网 发布:java人工智能 编辑:程序博客网 时间:2024/06/04 21:59
【题意】:获得最大循环长度。
【注意】:题目并不是一定按照第一二个数小于等于第二个数输入。如果不是,需要交换。。虽然这种数据感觉很无聊不过在题目中有提示的,The integers i and j must appear in the outputin the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
【AC代码】:
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>#include <iomanip>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */int getLength(int a){int cnt = 1;while (a!=1){cnt++;//evenif (0==a%2)a = a/2;elsea = 3*a+1;}return cnt;}int main(int argc, char** argv) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int a = 0, b = 0;while (cin >> a >> b){int m = 0, n = 0;m = a < b?a:b;n = a < b?b:a;int i = 0, max = -1;for (i = m; i <=n; i++){if (max < getLength(i))max = getLength(i);}cout << a << " " << b << " " << max << endl;}return 0;}
0 0
- HDOJ 1032 The 3n + 1 problem(水)
- 【HDOJ】1032 -> The 3n + 1 problem
- hdoj 1032 The 3n + 1 problem
- HDOJ 1032 The 3n + 1 problem
- HDOJ The 3n + 1 problem 1032
- HDOJ 1032 The 3n + 1 problem
- HDOJ 1032 The 3n+1 problem
- hdoj-1032-The 3n + 1 problem
- HDOJ 1032(POJ 1207) The 3n + 1 problem
- hdoj 1032 The 3n + 1 problem(细节细节)
- HDOJ 1032 The 3n + 1 problem解题报告
- hdoj.1032 The 3n + 1 problem 20140726
- Hdoj 1032 The 3n+1 problem (看题目很重要)
- HDOJ The 3n + 1 problem(Java)
- ACM--次数最多--HDOJ 1032--The 3n + 1 problem--水(数据太弱)
- 杭电OJ(HDOJ)1032题:The 3n + 1 problem(穷举,水题)
- HDOJ, 杭电1032, The 3n+1 problem. POJ, 北大OJ,1207....数学题。。又一发
- hdu 1032 The 3n + 1 problem
- Flex4.5中datagrid加入图片image显示
- 成语接龙(Idiomatic Phrases Game)
- POJ 3414 Pots 广度优先搜索+记忆化
- hibernate缓存:一级缓存和二级缓存
- Lua总结二
- HDOJ 1032 The 3n + 1 problem(水)
- PR4E第五周作业
- 经典贪吃蛇小游戏
- MFC在对话框中添加了一个richedit控件,窗口就不显示了。
- 应用DOM方式解析XML
- 工厂方法模式
- Java_IO流
- 单元测试——Moq框架下的Mock简介及简单实例
- MySQL数据库初学