开元周游
德国频道
查看: 1602|回复: 0
打印 上一主题 下一主题

爱尔兰根大学参加今年ACM大赛,内部选拔样题

[复制链接]
1#
发表于 8.4.2003 22:03:59 | 只看该作者
The 3n + 1 problem  <br><br>Background<br>roblems 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. <br><br>The Problem<br>Consider the following algorithm: <br><br> <br>                1.                  input n<br><br>                2.                  print n<br><br>                3.                  if n = 1 then STOP<br><br>                4.                 if n is odd then n/2   <br><br>                5.                  else 3n+1   <br><br>                6.                  GOTO 2<br><br><br>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 <br><br>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 &lt; n &lt; 1,000,000 (and, in fact, for many more numbers than this.) <br><br>Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. <br><br>For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j. <br><br><br>The Input<br>The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. <br><br>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. <br><br><br>The Output<br>For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one 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). <br><br><br>Sample Input<br><br>1 10<br>100 200<br>201 210<br>900 1000<br><br><br>Sample Output<br><br>1 10 20<br>100 200 125<br>201 210 89<br>900 1000 174<br><br>
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

站点信息

站点统计| 举报| Archiver| 手机版| 小黑屋

Powered by Discuz! X3.2 © 2001-2014 Comsenz Inc.

GMT+1, 7.2.2025 10:03

关于我们|Apps

() 开元网

快速回复 返回顶部 返回列表