ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

题目地址:
         http://acm.hdu.edu.cn/showproblem.php?pid=1032

水题,不解释..........................

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋

#include
<stdio.h>
int Length(int n)
{
     
int k=0;
     
while(n!=1)
     {
           
if(n%2==1)
                 n
=3*n+1;
           
else
                 n
/=2;
           k
++;
     }
     
return (k+1);
}
int main( )
{
     
int i,j,temp,max,t,small,large; 
     
while(scanf("%d",&i)!=EOF) 
     {
           scanf(
"%d",&j);
           
if(i<=j)
           {
            small
=i;large=j;
           }
           
else { 
                 small
=j;large=i;
                 }   
           temp
=small;
           max
=Length(temp);
           
while(temp<=large)
           {
                 t
=Length(temp);
                 
if(t>max)
                       max
=t;
                 temp
++;
           }
           printf(
"%d %d %d\n",i,j,max);
     }
     
return 0;
}

Feedback

# re: HDOJ HDU 1032 The 3n + 1 problem ACM 1032 IN HDU   回复  更多评论   

2010-09-18 20:13 by syx
水题 不解释 帮白哥顶个!

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理