"Search" HDU 5323 Solve This interesting problem

Source: Internet
Author: User

Click to open link

Build by line tree [0, N]

Known [L, r] nodes to find n

If you build a line tree [0, 2*r] This is the singular of the total number of points (left subtree!). = Right Sub-tree

[0, R] in Shari n Max is 2*r

If a line segment tree [0, 2*r+1] is built (left subtree = = right subtree)

[0, R] in the left subtree then [0, R] can build

So when the search is over 2*r, return directly.

#include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iostream > #include <algorithm> #include <sstream> #include <cmath>using namespace std; #include <queue > #include <stack> #include <vector> #include <deque> #define Cler (arr, Val) memset (arr, Val, sizeof ( ARR)) #define for (I,A,B) for (int. i=a;i<=b;i++) #define IN Freopen ("In.txt", "R", stdin), and #define out freopen ("out". TXT "," w ", stdout); typedef long LONG ll;const int MAXN = 101000;const int MAXM = 200000;const int INF = 0x3f3f3f3f;cons t int mod = 1000000007;const double eps= 1e-8; #define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1ll ans,flag,l,r; void Dfs (LL l,ll r) {if (r>2*r| |    Flag&&r>=ans) return;        if (l==0) {flag=1;        Ans=r;    return;    } LL len=r-l+1;    if (l-len-1>=0) DFS (L-LEN-1,R);    if (l-len>=0) DFS (L-LEN,R);    DFS (L,R+LEN-1); DFS (L,r+len);} int main () {while (scanf ("%i64d%i64d", &l,&r)!=eof) {ans=inf;flag=0;        DFS (L,R);        if (Ans==inf) puts ("-1");    else printf ("%i64d\n", ans); } return 0;} /**/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Search" HDU 5323 Solve This interesting problem

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.