Two-fork Tree
The left and right nodes of node K are 2k and 2k+1 respectively.
Ball Drop
Place the ball on the first node and fall, each point has a switch (the ball falls at that point when the state will change), when the point is closed to the left, or to the right, the first ball fell on the node
Simulate directly according to test instructions
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN = -;5 ints[1<<MAXN];6 intMain () {7 intd,i;8 while(SCANF ("%d%d", &d, &i) = =2){9memset (s),0,sizeof(s));Ten intK, n = (1<<D)-1; One for(inti =0; i < I; i++){ AK =1; - for(; ; ) { -S[K] =!S[k]; thek = S[k]? k*2: k*2+1; - if(k > N) Break; - } - } +printf"%d\n", k/2); - } + return 0; A}
If you continue to observe, you will find the law, each odd and even different ball falls around the same
Just know that the ball is the first few fall on the node can know the closure of the point switch, that is, the ball of the left and right
This can save a lot of time and unnecessary arrays
1#include <cstdio>2#include <cstring>3 using namespacestd;4 intMain () {5 intd,i;6 while(SCANF ("%d%d", &d, &i) = =2){7 intK =1;8 for(inti =0; I < D1; i++){9 if(i&1){TenK = k*2; I = (i+1)/2; One } A Else{ -K = k*2+1; I/=2; - } the } -printf"%d\n", k); - } - return 0; +}
Wenbao and two fork tree