小球滚二叉树代码
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int key;
}node;
int up(int a,int n)
{
int i,s=1;
for(i=0;i<n;++i)
s *= a;
return s-1;
}
int ac(int D,int I)
{
int i,max = up(2,D),j,ans;
printf("%d\n",max);
node *a = (node*)malloc(sizeof(node)*max+1);
for(i=0;i<=max;++i)
{
a[i].key = 0;
}
for(i=1;i<=max;)
{
if(I%2)
{
ans = i;
i *=2;
I = I/2+1;
}
else
{
ans = i;
i = i*2+1;
I /= 2;
}
}
return ans;
}
int main()
{
printf("%d",ac(4,2));
return 0;
}