第五届山东省ACM Full Binary Tree

Full Binary Tree

在满二叉树中求两个节点的最近距离

#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<cstdlib>  
#include<iostream>  
#include<algorithm>  
#include<vector>  
#include<map>  
#include<queue>  
#include<stack>  
#include<string>  
#include<map>  
#include<set>  
#include<ctime>  
#define eps 1e-6  
#define MAX 100005  
#define INF 0x3f3f3f3f  
#define LL long long  
#define pii pair<string,int>  
#define rd(x) scanf("%d",&x)  
#define rd2(x,y) scanf("%d%d",&x,&y)  
const int dir[][2] = { {-1, 0}, {0, -1}, { 1, 0 }, { 0, 1 } };  
using namespace std;  
int main(){  
  int n,x,y;  
  rd(n);  
  while(n--){  
    rd2(x,y);  
    int step=0;  
    while(x!=y){  
        x>y?x/=2:y/=2;  
        step++;  
    }  
    printf("%d
",step);  
  }  
  return 0;  
}  


原文地址:https://www.cnblogs.com/zswbky/p/6717957.html