title: ACM dropping balls
body: <p>Below is the code that I have copied from link <a href="http://progspedia.blogspot.com/2011/05/679-dropping-balls.html#comment-form" rel="nofollow">http://progspedia.blogspot.com/2011/05/679-dropping-balls.html#comment-form</a></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int t,D,I,P,i,j;
      //freopen("in.txt","r",stdin);
  
      while(scanf("%d",&amp;t)==1&amp;&amp;t&gt;0)
      {
          for(i=0;i&lt;t;i++)
          {
              scanf("%d%d",&amp;D,&amp;I);
              P=1;D--;
  
              for (j=0;j&lt;D;j++)
              {
                  P= I&amp;1 ? (P&lt;&lt;1) : (P&lt;&lt;1)+1;
                  I=(I+1)&gt;&gt;1;
              }
              printf("%d\n",P);
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>The code runs perfectly but I don't understand how this code keeps tracks of the thing that which sub tree we have to go after level 1. If someone helps me in that that would be very helpful for me.</p>
  
  <p>Link to the problem is <a href="http://uva.onlinejudge.org/index.php?option=onlinejudge&amp;page=show_problem&amp;problem=620" rel="nofollow">http://uva.onlinejudge.org/index.php?option=onlinejudge&amp;page=show_problem&amp;problem=620</a></p>