Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=1032

注意m>n的情况

View Code
 1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int f(int x)
5 {
6 int c=1;
7 while (x!=1)
8 {
9 if (x%2==0) x/=2;
10 else x=x*3+1;
11 c++;
12 }
13 return c;
14 }
15 int main()
16 {
17 int m,n;
18 int ans,t;
19 int i;
20 while (scanf("%d%d",&m,&n)!=EOF)
21 {
22 ans=0;
23 for (i=m;i<=n;i++)
24 if ((t=f(i))>ans) ans=t;
25 for (i=m;i>=n;i--)
26 if ((t=f(i))>ans) ans=t;
27 printf("%d %d %d\n",m,n,ans);
28 }
29 return 0;
30 }

 

posted on 2011-11-30 19:48  Qiuqiqiu  阅读(104)  评论(0编辑  收藏  举报