HDU 5323 SOLVE This interesting problem explosion search

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.