The main topic: Give a completely binary tree, each node has a switch, just start the switch is open, the ball passes through the node after the switch is closed (except the root node). If the ball passes through the node's sibling node, then the switch on the node opens again.
Now put the ball to the root node, preference to the left node to go, if the left node switch off, select the right. After the ball falls to the leaf node, the other ball continues, asking the nth ball to which leaf node it falls.
Problem-solving ideas: In fact, this problem is quite water, because it is two fork tree, so can be determined by the ball's odd and even line to determine which branch to go, if n 2 = = 0 is the nth to the right to go, and vice versa is to go to the left, and so on to launch the last ball fell where
#include <cstdio>#include <cstring>using namespace STD;intMain () {intD, L;scanf("%d", &d); while(scanf("%d", &d) = =1&& D! =-1) {scanf("%d", &l);intCur =1, ans =1; while(Cur < (1<< D) {ans = cur; Cur *=2;ifL2==0) cur++; L = (L +1) /2; }printf("%d\n", ans); }return 0;}
Balls regularity of UVA-679 dropping