题目传送门

 /*
题意:告诉一个区间[L,R],问根节点的n是多少
DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - len -1,r];
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std; typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll INFL = 1e30;
ll ans; void DFS(ll l, ll r) {
if (l > r || l < ) return ;
if (l == ) {
ans = min (ans, r); return ;
}
ll len = r - l + ;
if (l < len) return ;
DFS (l, r + len);
if (len != ) DFS (l, r + len - );
DFS (l - len, r); DFS (l - len - , r);
} int main(void) { //HDOJ 5323 Solve this interesting problem
//freopen ("H.in", "r", stdin); ll L, R;
while (scanf ("%I64d%I64d", &L, &R) == ) {
if (L == ) {
if (R >= L) printf ("%I64d\n", R);
else puts ("-1");
continue;
}
ans = INFL; DFS (L, R);
printf ("%I64d\n", (ans == INFL) ? - : ans);
} return ;
}

DFS+剪枝 HDOJ 5323 Solve this interesting problem的更多相关文章

  1. HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜

    pid=5323" target="_blank" style="">链接 Solve this interesting problem Tim ...

  2. 2015 Multi-University Training Contest 3 hdu 5323 Solve this interesting problem

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. hdu5323 Solve this interesting problem(爆搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Solve this interesting problem Time Limit ...

  4. H - Solve this interesting problem 分类: 比赛 2015-07-29 21:06 15人阅读 评论(0) 收藏

    Have you learned something about segment tree? If not, don't worry, I will explain it for you.  Segm ...

  5. 多校赛3- Solve this interesting problem 分类: 比赛 2015-07-29 21:01 8人阅读 评论(0) 收藏

    H - Solve this interesting problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I ...

  6. hdoj 5113 Black And White DFS+剪枝

    Black And White Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...

  7. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  8. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  9. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

随机推荐

  1. c/c++常用代码 -- 共享内存

    #pragma once #include <stdio.h> #include <tchar.h> #include <string.h> #include &l ...

  2. python djange输入中文错误的解决办法

    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) ...

  3. ubuntu下xampp的安装

    转载:http://blog.csdn.net/zhoushengchao/article/details/6006584 首先,请从www.xampp.org下载最新版XAMPP.然后,将安装文件服 ...

  4. 62.在cdc文件上某些例化模块看不到的原因

    比如在顶层文件中,例化了几个模块,综合后打开cdc文件,会在structure/net中少几个例化模块,即看不到,但在顶层文件中还是存在的,只是ISE软件综合的问题而已,原因是在顶层或子模块中,有些应 ...

  5. 42.JTAG接口使用注意

    无论是客户反馈,还是自己亲身经历,USB-Blaster不能下载配置FPGA的情况时有出现.究其原因,大致有如下几条: 1. FPGA器件上的JTAG相关引脚出现故障: 2. USB-Blaster坏 ...

  6. mysql 字段编码该为utf8mb4

    alter table c_comment modify column content varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unico ...

  7. htaccess 探秘

    .htaccess访问控制(Allow/Deny) 1. 验证是否支持.htaccess 在目录下新建一个.htaccess 文件,随笔输入一串字符(毫无意义),看看什么反应,如果是500错误,说明目 ...

  8. gvim编辑文件到github乱码

    with below _vimrc settings, code uploaded to GitHub will display with proper encoding set encoding=u ...

  9. Spring与apache CXF结合实例

    本文的前提是已经有一个Spring的项目,在此基础上如何跟apache CXF进行结合,开发出WebService服务和调用WebService服务. 1.开发WebService   1.引入jar ...

  10. TEST ON 平安夜

    1.前言 = = 感觉自己其实没发过关于考试的博客过... 今天是一个平安的夜晚,漆黑的夜被霓虹划分成网络,很适合发题. 2.num9九数码问题 传统8数码改一下...只询问一个状态,所以很容易搞,正 ...