hdu1032解题报告

来源:互联网 发布:大数据入门 知乎 编辑:程序博客网 时间:2024/05/16 04:42

思路:题的大意是输入两个数(注意,这里没有说第一个数一定要小于第二个数),然后对这两个数之间的所有整数包括端点的数,进行一种规律运算,并求出运算的次数,比较所有的数规律运算次数,输出最大的

编程语言:C语言

代码如下:

#include<stdio.h>
void main()
{
 __int64 n, m, i, temp;
 while (scanf("%I64d%I64d", &n, &m) != EOF)
 {
  __int64 max = 0, x = 0, y = 0;
  printf("%I64d %I64d ", n, m);
  if (n > m)
  {
   max = n;
   n = m;
   m = max;
   max = 0;
  }
  for (i = n; i <= m; i++)
  {
   __int64 step = 0, t;
   t = i;
   while (1)
   {
    if (t == 1)
     break;
    if (t % 2 != 0)
    {
     t = 3 * t + 1;
     step = step + 1;
     continue;
    }
    else
    {
     t = t / 2;
     step = step + 1;
     continue;
    }
   }
   temp = step + 1;
   if (max < temp)
    max = temp;
  }
  printf("%d\n", max);
 }
}


0 0