原题链接:传送门
太狗了。。33%的数据是i > j的
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int ans, i, j;
int book[N];
int work(int n){
int step = 1;
while(1){
if(n % 2 == 0) n /= 2;
else n = 3*n+1;
step++;
if(n == 1) break;
}
return step;
}
int mx(int a, int b){
for (int k = a; k <= b; ++k){
book[k] = work(k);
}
ans = book[a];
for (int k = a; k <= b; ++k){
if(book[k] > ans) ans = book[k];
}
return ans;
}
int main(){
while(cin >> i >> j){
memset(book, 0, sizeof book);
int temp;
if(i > j) {
temp = i;
i = j;
j = temp;
cout << j << ' ' << i << ' ' << mx(i, j) << endl;
}
else cout << i << ' ' << j << ' ' << mx(i, j) << endl;
}
return 0;
}