您的位置:首页 > 其它

HDU 1032 水题

2011-08-01 08:14 337 查看
/*
* Author:lonelycatcher
* problem:heu 1032
* type:纯水题
*/
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<string.h>
using namespace std;
int fun(int x)
{
int i=1;
while(x!=1)
{
if(x&1)
{
x=3*x+1;
}else
{
x=x>>1;
}
i++;
}
return i;
}
int main()
{
setbuf(stdout,NULL);
int left,right,max,i,j;
while(scanf("%d %d",&left,&right)!=EOF)
{
max=0;
if(left<right)
{
for(i=left;i<=right;i++)
{
int sum=fun(i);
if(sum>max)
{
max=sum;
}
}
}
else
{
for(i=right;i<=left;i++)
{
int f=fun(i);
if(f>max)max=f;
}
}
printf("%d %d %d\n",left,right,max);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: