Talk:UVa 679 - Dropping Balls

ONE SOLUTION In any sub-tree, even numbered ball to that sub-tree's root goes to right and odd numbered to the left. So using this fact we can make following function

int subtree(int depth ,int i,int root) {   if(depth==1) return root; else if(i%2==0) return subtree(depth-1,i/2, 2*root+1); else return subtree(depth-1, (i+1)/2, 2*root); }

Link : Online Compiler