hdoj-1032-The 3n + 1 problem(坑题)

 题目链接

//巨坑的一道题,输入的m,n要判断大小,输出还要按照原来的顺序,范围还是i<=n<=j

#include <iostream> 
#include <cstdio>
#include <algorithm>
using namespace std;
int alro(int x) {
    int ct = 1;
    while (x != 1) {
        if (x & 1) x = 3*x+1;
        else x = x/2;
        ct++;
    }
    return ct;
}
int main() {
    int m,n;
    while (cin>>m>>n) {
        int sm = min(m ,n);
        int lar = max(m ,n);
        int maxn = 0;
        for (int i=sm; i<=lar; i++) {
            maxn = max(alro(i), maxn);
        }
        printf("%d %d %d\n", m, n, maxn);
    }
    return 0;
}

 

posted @ 2018-05-03 21:21  朤尧  阅读(236)  评论(0编辑  收藏  举报