HDU 5323 solve this interesting problem burst search, hdu5323

Source: Internet
Author: User

HDU 5323 solve this interesting problem burst search, hdu5323

Link

Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 511 Accepted Submission (s): 114


Problem DescriptionHave you learned something about segment tree? If not, don't worry, I will 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 has two values: Lu And Ru .
-If Lu = Ru , U is a leaf node.
-If Lu =ru , U has two children x and y, Lx = Lu , Rx = running Lu + Ru2 failed ⌋ , Ly = direction Lu + Ru2 direction + 1 , Ry = Ru .
Here is an example of segment tree to do range query of sum.



Given two integers L and R, Your task is to 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 Lu = L And Ru = R .
 
InputThe input consists of several test cases.
Each test case contains two integers L and R, as described above.
0 ≤ L ≤ R ≤ 109
LR −l + 1 ≤ 2015
 
OutputFor each test, 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
For a given interval [l, r], build (1, n) using the recursive build method of the line tree and ask what the minimum n is, so that build (1, n) you can directly create the interval [l, r]. Train of Thought: Pay attention to the range. Then, you can estimate that the distance between the interval and the root node is no more than 10, so you can search from the bottom up.

Code

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.