Question: there is a full binary tree. Each node is a switch. It is closed at first, and the ball falls from the vertex,
Each time the ball goes through the switch, it will reverse its status. Now, I want to ask the Switch number that the K ball goes through when it falls to layer D.
Analysis: hexadecimal encoding. After several simulation times, we can see that the ball will make the switch form a continuous binary number representation (the root is low ).
When the k-th ball is placed, the switch status is exactly the K of the binary value. You can use the remainder of mod 2 to determine the direction.
Note: Observe the regular simulation process.
# 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 ;}
Ultraviolet A 679-dropping bils