OJ-Problems-Source/CodeVS/2969_冰封.cpp

46 lines
631 B
C++
Raw Normal View History

2016-07-06 14:28:18 +08:00
/*
:
:p2969
*/
#include <stdio.h>
const int size = 10000000;
int cnt;
int save[size];
void dfs(int cur){
if(cur == 1) return ;
cnt++;
dfs(cur % 2 ? cur * 3 + 1 : cur / 2);
}
int main(int argc, char* argv[]){
int tot;
save[1] = 0;
scanf("%i", &tot);
while(tot--) {
int a, b, max = 0;
scanf("%i%i", &a, &b);
if(a > b) {
int x = a;
a = b;
b = x;
}
for(; a <= b; a++) {
if(save[a]) {
cnt = save[a];
if(cnt > max) max = cnt;
continue ;
}
cnt = 0;
dfs(a);
save[a] = cnt;
if(cnt > max) max = cnt;
}
printf("%i\n", max);
}
return 0;
}