The whereabouts of the little monkey

Source: Internet
Author: User

Small monkey Fall time limit: theMs | Memory Limit:65535KB Difficulty:3
Describe

There is a binary tree with a maximum depth of D, and all leaves have the same depth. All nodes are numbered 1,2,3,,2 from left to right from top to bottom minus 1 for D-Times. Put a little monkey at the junction 1 and it will run down. Each inner node has a switch, the initial all closed, when a small monkey ran to a switch, its state will change, when reaching an internal node, if the switch is closed, the small monkey go left, or go to the right, until the leaf node.

Some little monkeys began to run down from the Junction 1, where did the last little monkey go?

Input
enter the depth of the binary tree leaves D, and the number of small monkeys I, assuming I do not exceed the number of leaves of the whole tree, d<=20. End With 0 0
Output
output the number of the leaf where I have a small monkey.
Sample input
4 23 40 0
Sample output
127
Code:
#include <stdio.h>int main (void) {int m,n;while (scanf ("%d%d", &m,&n)!=eof){Long Long count=1;int i;if (m==0&&n==0)BreakElse{for (i=1;i<m;i++){if (n%2==1){count=count*2;n= (n+1)/2;}Else{count=count*2+1;N=N/2;}}printf ("%lld\n", count);}}return 0;}

The whereabouts of the little monkey

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.