Description

Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.
Consider the following algorithm:

```
1. 		 input n

2. 		 print n

3. 		 if n = 1 then STOP

4. 		 		 if n is odd then   n <-- 3n+1

5. 		 		 else   n <-- n/2

6. 		 GOTO 2

```

Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)

Given an input n, it is possible to determine the number of numbers printed before the 1 is printed. For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.

For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
（是i和j之间数的循环次数最大的）

```#include<iostream>
using namespace std;
int  bb(int i)
{     int count=1;
while(i!=1)
{
if(i%2==0)i/=2;
else i=i*3+1;
count ++;

}

return count;

}
int main()
{

int a,b;
int q=0;
while(cin>>a>>b)
{
q++;
if(q>=10000)break;
int d=a>b?a:b;
int c=a<b?a:b;
int maxa=0;
for(int j=c;j<=d;j++)
{
int  a1=bb(j);
if(maxa<a1)maxa=a1;
}
cout<<a<<" "<<b<<" "<<maxa<<endl;

}

return 0;
}
```

## poj-1207 THE 3n+1 problem的更多相关文章

1. OpenJudge/Poj 1207 The 3n + 1 problem

1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

2. The 3n + 1 problem 分类： POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏

The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53927   Accepted: 17 ...

3. UVa 100 - The 3n + 1 problem（函数循环长度）

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

4. 烟大 Contest1024 - 《挑战编程》第一章：入门 Problem A: The 3n + 1 problem（水题）

Problem A: The 3n + 1 problem Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 6[Submit][St ...

5. uva----(100)The 3n + 1 problem

The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

6. 【转】UVa Problem 100 The 3n+1 problem （3n+1 问题）——（离线计算）

// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...

7. 100-The 3n + 1 problem

本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...

8. PC/UVa 题号: 110101/100 The 3n+1 problem （3n+1 问题)

The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

9. UVA 100 - The 3n+1 problem （3n+1 问题）

100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...

10. classnull100 - The 3n + 1 problem

新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正  The 3n + 1 problem  Background Problems in Computer Science are o ...

## 随机推荐

1. Atitit.电脑图片与拍摄图片的分别

Atitit.电脑图片与拍摄图片的分别 1. Extname都是jpg的..1 1.1. 数码照片的Exif信息, 1 1.2. 是否有人脸1 1.3. 是否skin图1 1.4. 是否大面积色素单一 ...

2. android项目中gen目录不能自动生成R.java的原因

1.调用的资源文件不存在:xml文件中有些控件没有关联引用:把项目缺少的文件加上,包括资源文件,如 values中的strings.xml或者图片等资源. 2.项目中缺少必须的系统文件(比如:defa ...

3. window下安装oracle数据库

Oracle 11g安装 1.解压下载的包,然后进入包内,点击setup.exe开始安装 . 2.出现如下:一般把那个小对勾取消,点击下一步进行, 弹出下图这个后点‘是’ 3.下图后,选择创建和配置数 ...

4. ANDROID_MARS学习笔记_S01_010日期时间控件

1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

5. cal命令详解与练习

cal: 显示日历. 命令格式: cal [-smjy13] [[[day] month] year] 参数说明 -1 显示当前月日历 -3 显示当前月前后3月的日历 -s 以星期天为第一天显示 -m ...

6. oracle 空置排在最后显示

nulls last select * from emp order by comm select * from emp order by comm desc select * from emp or ...

7. 什么是野指针？（What is a wild pointer?）

未被初始化的变量称为野指针(wild pointer).顾名思义,我们不知道这个指针指向内存中的什么地址,使用不当程序会产生各种各样的问题. 理解下面的例子: int main() { int *p; ...

8. oracle 包，函数，过程，块的创建和执行及在java中执行(转)

SQL> create or replace procedure sp_guocheng1 is--如果有这个名字就替换  2  begin--执行部分  3  insert into guoc ...