UVA100 The 3n + 1 problem

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36

简单模拟题。

#include<stdio.h>
#include<iostream>
using namespace std;
int len[1000001];
int main()
{
    int i,a,b,a1,b1;
    long long j;
      for (i=1;i<=1000000;i++)
        {
           j=i;
           int k=1;
           while (j!=1)
            {
                if (!(j&1)) j=j>>1;
                else j=j*3+1;
                k++;
            }
           len[i]=k;
        }
    while (scanf("%d%d",&a,&b)!=EOF)
    {
    int temp=0;
    a1=a;b1=b;
     if (a>b)
     {
         temp=a;
         a=b;
         b=temp;
     }
     int maxx=len[a];
     for (i=a+1;i<=b;i++)
       if (maxx<len[i]) maxx=len[i];
          printf("%d %d %d\n",a1,b1,maxx);
    }
    return 0;
}
时间: 2024-11-09 23:47:02

UVA100 The 3n + 1 problem的相关文章

The 3n + 1 problem

The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 50648   Accepted: 16059 Description Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In th

POJ1207 The 3n + 1 problem

这题不是很难,模拟一下即可,但有一些细节需要注意 输入的数不一定升序,且要按原顺序输出,还有就是读完数据的问题 The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53006   Accepted: 16841 Description Problems in Computer Science are often classified as belonging to a certain cl

The 3n + 1 problem(杭电1032)(暴力求解)

The 3n + 1 problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23163    Accepted Submission(s): 8653 Problem Description Problems in Computer Science are often classified as belonging to a

The 3n + 1 problem(南阳oj271)(打表法)

The 3n + 1 problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Problems 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 algorith

HDU 1032.The 3n + 1 problem【注意细节】【估计数据不强】【8月21】

The 3n + 1 problem Problem Description Problems 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 classificat

HDU 1032 The 3n + 1 problem【递归】

/* 中文题目 3n+1问题 中文翻译-大意 当一个数n是奇数的时候变成3*n+1,为偶数的时候变成n/2 解题思路:区间内每个数逐个求解 难点详解:如何逐个计算每个数的次数,选用while循环,还有就是将此时的 i 值赋给data,用于while循环的条件.最后再将这一个数运算次数累加在一起 关键点:理解题意 解题人:lingnichong 解题时间:2014-06-03 09:40:39 解题体会:没有告诉你那个大那个小,要先比较一下数,是个陷阱 */ The 3n + 1 problem

HDU 1032 The 3n + 1 problem (这个题必须写博客)

The 3n + 1 problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22148    Accepted Submission(s): 8276 Problem Description Problems in Computer Science are often classified as belonging to a c

HDU 1032.The 3n + 1 problem【注意细节】【预计数据不强】【8月21】

The 3n + 1 problem Problem Description Problems 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 classificat

100 - The 3n + 1 problem

题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36  The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a certain class of problem