HDU 5323 (2015 Multi-school 3)-Solve this interesting problem (dfs + pruning), hdu5323
Address: HDU 5323
Question: Give an l, r, indicating the interval [l, r]. Ask if there is a node interval of a line segment tree with a range of [0, n]: [l, r]. if the minimum n value is obtained,-1 is not output.
Idea: Because L/(R-L + 1) <= 2015, according to the nature of the Line Segment tree each time the number of the interval is increased by two times, so it can be concluded that there are almost 22 layers, therefore, you can use the pop-up search function to expand the [l, r] range until the value of l = 0 is met. Cut and pruning 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 LL; const int inf = 0x3f3f3f3f; const double pi = acos (-1.0); const double esp = 1e-8; int ans; int dfs (int l, int r) {if (l <0) retu Rn ans; // controls the left boundary if (! L) {// Save the currently smallest right boundary ans = min (ans, r); return ans;} if (2 * l <r + 1) return ans; // pruning. It is equivalent to four situations: directly output and return r. Dfs (l, 2 * r-l + 1); dfs (l, 2 X r-l); dfs (2 * l-r-1, r); dfs (2 * l-r-2, r);} int main () {int l, r; while (~ Scanf ("% d", & l, & r) {ans = inf; ans = dfs (l, r); if (ans = inf) puts ("-1"); else printf ("% d \ n", ans);} return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.