6_6 ball Drop (UVa679) < full binary tree numbering >

Source: Internet
Author: User

There are k balls from one complete binary tree (fully binary TREE,FBT) root (root) down one by one. When the ball encounters a non-terminal node, it may run toward the left subtree, or to the right subtree, until the ball reaches the end node (that is, the leaves). The decision to turn the ball to the left or right at a non-terminal node is controlled by a 2-value true,false. If the current value of this non-terminal node is false, the ball will go to the left subtree when it comes, but this value will become true. If the current value of this non-endpoint is true, the ball will go to the right subtree when it comes, but this value will change to false. Note: At the beginning, all non-endpoint values are false. In addition, all nodes in the complete binary tree are sequentially numbered, from top (depth = 1) to bottom, left to right. Please refer to.

For example, the above figure is a full binary tree with a depth of 4. The first ball falls down and goes through nodes 1, 2, 4, and finally in node 8. The second ball goes down and then it goes through nodes 1, 3, and 6 and finally falls in node 12. The third ball goes down. Nodes 1, 2, and 5 finally fall in node 10.
Give you the depth of the full binary tree D as well as the falling ball of the first I, please write a program to calculate the number of the I-ball falling on the terminal node.

Input
The first column of the input has an integer that represents the following set of test data.
Each set of test data is listed with 2 integers d,i (2 <= D <= 20,1 <= I <= 524288). You can assume that I will not exceed the number of end nodes.
Output
For each set of test data output a column, the I ball falls on the end node number.

6_6 ball Drop (UVa679) < full binary tree numbering >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.