解题报告_18.5.8_POJ_1207

注意要交换顺序

处理的时候交换了顺序,输出的时候还是要保持原来的顺序

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<cstring>
using namespace std;
int main() {
    //freopen("in.txt","r",stdin);
    int n, m,sum,tmp;
    while(scanf("%d%d", &n, &m) != EOF) {
        bool flag = 1;
        if(n>m) {
            flag = 0;
            int tmp = n;
            n = m;
            m = tmp;
        }
        sum = 0;
        for(int i = n; i <= m; i++) {
            tmp = 0;
            int j = i;
            while(j != 1) {
                tmp++;
                if(j%2 == 1) j = 3*j + 1;
                else j /= 2;
            }
            if(tmp > sum) sum = tmp;
        }
        if(flag)printf("%d %d %d\n",n,m,sum+1);
        else printf("%d %d %d\n",m,n,sum+1);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/huangming1644/article/details/80242160