poj1207 The 3n + 1 problem
来源:互联网 发布:淘宝卖家快递合作价格 编辑:程序博客网 时间:2024/06/06 06:38
题意:有个算法,n为奇数 n=3n+1,n为偶数,n=n/2,得到的值在不断循环这个过程,直到为1则停止,求出i,j之间的数中循环最多的次数
思路:对于i,j之间的每个数数进行判断,不断更新最大循环次数
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){int i,j;int t=-1;while((scanf("%d%d",&i,&j)!=EOF)){ if(i>j) { t=j; j=i;i=t; } int maxn=0,z=1; for(int p=i;p<=j;p++){ int k=p; while(k!=1){ if(k%2==0){ k/=2; z++; } else {k=3*k+1;z++;} } maxn=max(maxn,z); z=1; } if(t==-1) cout<<i<<" "<<j<<" "<<maxn<<endl; else cout<<j<<" "<<i<<" "<<maxn<<endl; t=-1;}}
0 0
- 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
- poj1207——The 3n + 1 problem
- POJ1207,The 3n + 1 problem,水输出要注意...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
- poj1207-the 3n+1 problems
- 北大暑假训练计划—POJ1207 The 3n + 1 problem(C语言)
- poj1207(3n+1)
- The 3n + 1 problem
- The 3n+1 Problem
- The 3n + 1 problem
- The 3n + 1 problem
- The 3n + 1 problem
- js (call()你不懂的)“继承的实现”
- xml中cdata节和注释的区别
- C语言库stdio.h操作
- Python 3.2 入门教程
- popupWindow 实现菜单
- poj1207 The 3n + 1 problem
- wampserver环境配置--Apache2.4+PHP5.6+Mysql5.7.11
- IOS UIButton的属性总结
- java 死锁及解决
- 解决php的“It is not safe to rely on the system’s timezone settings”问题
- 寄存器
- [我所知道的BIOS]->[DRAM Sizing] (1) 7
- python 简单的日k线 主要是时间转换
- bootstrap原理分析