Uva 100 The 3n+1 problem
2016-05-24 10:48
369 查看
#include<iostream> #include<cstdio> #include<string> #include<map> #include<algorithm> #include<vector> #include<queue> #include<set> #include<cstring> #include<stack> using namespace std; int count(int temp) { int total=1; while(temp!=1) { if(temp%2==0) temp=temp/2; else temp=3*temp+1; total++; } return total; } int main() { int i,j; while(scanf("%d %d",&i,&j)!=EOF) { int start=i; int end=j; int t; if(i>j) { t=i; i=j; j=t; } int maxxx=-1; while(i<=j) { int amount=count(i); if(amount>maxxx) maxxx=amount; i++; } printf("%d %d %d\n",start,end,maxxx); } return 0; }
相关文章推荐
- 从头认识多线程-2.25 synchronized同步方法在jvm是怎样执行的?
- linux md5 加密字符串和文件方法
- 设计模式之原则详细介绍
- 在 Perl 中利用 DOM 和 XPath 对 XML 进行有效处理
- linux md5 加密字符串和文件方法
- HBase 学习之一 <<HBase使用客户端API动态创建Hbase数据表并在Hbase下导出执行>>
- 蓝桥杯试题:矩阵翻硬币
- iOS开发UI篇-UITabBarController简单介绍
- echo 0 > /proc/sys/kernel/hung_task_timeout_secs disables this message
- Java程序中的“内存泄漏”问题
- 绘图神器 —— Graphviz 绘制数据结构相关图形
- Linux下对字符串进行MD5加密
- 二叉树-四种遍历及其他应用
- Android平台下Dalvik层hook框架ddi的研究
- form 表单总结
- 电商商品模型的设计
- 【日常笔记】java spring 注解读取文件
- Linux下对字符串进行MD5加密
- Linux下动态库和静态库的生成和使用
- Java本地方法(native方法)的实现