Link
Solve This interesting problemTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 511 Accepted Submission (s): 114
Problem Descriptionhave learned something about segment tree? If not, don ' t worry, I'll explain it for you.
Segment tree is a kind of binary Tree, it can be defined as this:
-For each node u in Segment Tree, u have the values: L u and R u .
-If Lu=R u , U is a leaf node.
-If Lu≠R u , u has both children X and Y,with lx=l u , R x =?< Span class= "Mi" id= "mathjax-span-48" style= "" >l u + r u 2 ? , Ly =?< Span class= "Mi" id= "mathjax-span-66" style= "" >l u + r u 2 ?+1 , ry=R u .
Example of segment tree to do range query of sum.
Given-integers L and R, Your task is-find the minimum non-negative n satisfy that:a Segment Tree with root node ' s Value Lroot =0 and rroot =n Contains a node U with lu=l and ru=r .
Inputthe input consists of several test cases.
Each test case contains the integers L and R, as described above.
0≤L≤R≤ 9
LR? L + 1 ≤
Outputfor each test, the output one line contains one integer. If there is no such n, just output-1.
Sample Input
6 710 1310 11
Sample Output
7-112
Source2015 multi-university Training Contest 3
Test instructions: The recursive build method for a given interval [l,r] with a segment tree builds (1, n) asking the minimum n is how much, so that the build (1,n) can be directly built in the interval [l,r] idea: Take a look at the scope, And then we can figure out that this interval is not more than 10 from the root node, so it's better to search from the bottom up.
Code
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5323 SOLVE This interesting problem explosion search