Title Address: HDU 5323
Test instructions: To a l,r, which represents the interval [l,r], and asks if there is a node interval for the segment tree of [0,n] is [l,r], if there is a minimum of n, if there is no output-1.
Idea: Because L/(r-l+1) <=2015, according to the nature of the line segment tree each partition between the sequence number expansion twice times, so can be obtained almost 22 layers, so with a burst search can be, from the [L,r] range continues to expand, until the l==0 until satisfied. Cut and prune by the way.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-8;intAnsintDfsintLintR) {if(l<0)returnAns//Control left Border if(!l) {//Save the current minimum right boundaryAns=min (ANS,R);returnAns }if(2*l<r+1)returnAns//Pruning. Equivalent to controlling the right border if(L==R) {the left border is equal to the right boundary without processing, direct output, returnR }//The following are four cases. DFS (L,2*r-l+1); DFS (L,2*R-L); Dfs2*l-r-1, R); Dfs2*l-r-2, r);}intMain () {intL,r; while(~scanf("%d%d", &l,&r)) {ans=inf; Ans=dfs (L,R);if(Ans==inf)puts("-1");Else printf("%d\n", ans); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5323 (2015 + school 3)-solve This interesting problem (dfs+ pruning)