这破题,根本看不懂题意啊。。。题意:一棵中序遍历是1 2 3 4 5...的满二叉树,从a a+1 a+2 a+3 b,总共多少步。x到y的距离为中间有多少个点。a > b没注意2Y。
#include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
int bin[];
int judge(int x)
{
int i,temp;
if(x <= )
return ;
for(i = ;i >= ;i --)
{
if(x&(<<i))
{
temp = x-(<<i);
if(temp)
return bin[i] + judge(temp) + i - ;
else
return bin[i];
}
}
return ;
}
int main()
{
int i,a,b;
bin[] = bin[] = ;
for(i = ;i <= ;i ++)
{
bin[i] = *bin[i-] + i-;
}
scanf("%d%d",&a,&b);
if(a > b)
swap(a,b);
printf("%d\n",judge(b)-judge(a));
return ;
}