Title: There is a complete two-fork tree, each node is a switch, initially completely closed, the ball is discarded from the vertex.
Each time the switch ball is reversed. Now ask the K ball to drop to D when the layer switch is number.
Analysis: Binary encoding. After several simulations, the ball will let the switch form a continuous binary number representation (the root is low).
When you put the K ball. The switch state is exactly the binary K. Using the remainder of modulo 2 to infer the direction is possible.
Explanation: The observation law simulates the processing to be possible.
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio>using namespace std; int main () {int n,r,l;while (CIN >> n && n >= 0) {while (n--) {cin >> l >> r;int k = 1;while (--L) {if (r%2) k = K<<1;else k = (k<<1) +1;r = (r+1) >>1;} cout << k << Endl;}} return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
UVa 679-dropping Balls