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