Title Link: Hdu 5323 Solve This interesting problem
Reverse thinking, every time to double the left or right, knowing that the left end of the 0 o'clock, that is exactly the case, the processing office all the situation to take the minimum value.
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef long ll; CONST LL inf = 0x3f3f3f3f;ll L, R, N;void Dfs (ll L, ll R) {//printf ("%lld%lld\n", L, R); if (l <= 0 | | R >= 2 * r) { if (L = = 0) N = Min (n, r); return;} int k = r-l + 1;if (k > L) Return;dfs (L-k, R);d FS (L-k-1, R);d FS (L, R + K), if (k > 1) DFS (l, R + k-1);} int main () {while (scanf ("%lld%lld", &l, &r) = = 2) {N = Inf;dfs (L, R);p rintf ("%lld\n", N = = INF. -1:n);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5323 Solve This interesting problem (DFS)