I - The 3n + 1 problem(2.4.2)
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
Output
line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
题目大意:给出两个数求在两个数之间的有最大循环长度的数,最大循环长度利用题目所给的3n+1解决问题的方法求出。
#include<stdio.h>
#include <iostream>
int arr[10001];
using namespace std;
int main()
{
int a,b;
int i;
arr[1]=1;
arr[2]=2;
for(i=3;i<10001;i++)
{
long long temp=i;
int cnt=0;
while(1)
{
if(temp&(0x01))
{
temp*=3;
temp+=1;
cnt++;
}
else
{
cnt++;
temp>>=1;
}
if(temp<i)
{
arr[i]=cnt+arr[temp];
break;
}
}
}
int t;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a>b)
{
t=a;
a=b;
b=t;
}
int max=0;
for(i=a;i<=b;i++)
{
if(max<arr[i])
{
max=arr[i];
}
}
printf("%d %d %d\n",a,b,max);
}
return 0;
}
I - The 3n + 1 problem(2.4.2)的更多相关文章
- UVa 100 - The 3n + 1 problem(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 烟大 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 ...
- 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 ...
- uva----(100)The 3n + 1 problem
The 3n + 1 problem Background Problems in Computer Science are often classified as belonging to a ...
- 【转】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 / ...
- 100-The 3n + 1 problem
本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
- 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 ...
- UVA 100 - The 3n+1 problem (3n+1 问题)
100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...
- classnull100 - The 3n + 1 problem
新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正 The 3n + 1 problem Background Problems in Computer Science are o ...
- The 3n + 1 problem
The 3n + 1 problem Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
随机推荐
- oracle数据库将一列的值拼接成一行,并且各个值之间用逗号隔开
使用场景:把某一列值转换为逗号分隔的字符串 例子:比如查询所有的的表空间如下,现在要获得所有的表空间用逗号分隔的字符串(比如rman duplicate的时候skip表空间) SQL> sele ...
- C语言判断文件夹或者文件是否存在的方法【转】
C语言判断文件夹或者文件是否存在的方法 方法一:access函数判断文件夹或者文件是否存在 函数原型: int access(const char *filename, int mode); 所 ...
- 复习下C 链表操作(双向循环链表,查找循环节点)
双向循环链表 和 单向循环链表 查找循环节点 思路都是一样. 快慢指针查找法. 理论可参考 c 链表之 快慢指针 查找循环节点 typedef struct Student_Double { ]; ...
- Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0
Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0 Uncaught (in ...
- vue项目使用webpack loader把px转换为rem
下载lib-flexible https://github.com/amfe/lib-flexible npm i lib-flexible --save 在main.js中引入lib-flexibl ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...
- 一篇文全面了解DevOps:从概念、关键问题、兴起到实现需求
一篇文全面了解DevOps:从概念.关键问题.兴起到实现需求 转自:一篇文全面了解DevOps:从概念.关键问题.兴起到实现需求 2018-06-06 目前在国外,互联网巨头如Google.Faceb ...
- java框架篇---hibernate之连接池
Hibernate支持第三方的连接池,官方推荐的连接池是C3P0,Proxool,以及DBCP.在配置连接池时需要注意的有三点: 一.Apche的DBCP在Hibernate2中受支持,但在Hiber ...
- Kylin 与 Spark SQL相比,有哪些差异和优势?
SparkSQL本质上是基于DAG模型的MPP.而Kylin核心是Cube(多维立方体).关于MPP和Cube预处理的差异,重复如下: > MPP [1] 的基本思路是增加机器来并行计算,从而提 ...
- Loadrunner C/S关联函数(LSP)AND(LSSS)使用-案例
LSP就是lrs_save_param()函数 LSSS就是lrs_save_searched_string()函数 一下我们用一个例子去说明他们的使用. C/S机制和B/S不一样,特别是有一个dat ...