DFS+剪枝 HDOJ 5323 Solve this interesting problem
/*
题意:告诉一个区间[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的更多相关文章
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
pid=5323" target="_blank" style="">链接 Solve this interesting problem Tim ...
- 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 ...
- hdu5323 Solve this interesting problem(爆搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Solve this interesting problem Time Limit ...
- 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 ...
- 多校赛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 ...
- hdoj 5113 Black And White DFS+剪枝
Black And White Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDOJ 1501 Zipper 【DP】【DFS+剪枝】
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 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 ...
随机推荐
- 自定义Drawable
本文由 伯乐在线 - treesouth 翻译,toolate 校稿.未经许可,禁止转载! 英文出处:ryanharter.com.欢迎加入翻译小组. 我们看过一些博客文章,讲述了为什么要适时地使用自 ...
- iOS 中使用md5加密
#import <CommonCrypto/CommonDigest.h> @implementation MD5Util +(NSString *)encode:(NSString *) ...
- 如何让webapi只返回json格式数据
最近脑子不好用,总记不住事,以前搞过让webapi只返回json格式的数据,今天有人问我又突然想不起了,后来总结一下,备忘一下,大概有下面几种处理方式 1.在WebApiConfig类的Registe ...
- 硬件描述语言Verilog设计经验总结
一.硬件描述语言Verilog 粗略地看Verilog与C语言有许多相似之处.分号用于结束每个语句,注释符也是相同的(/* ... */和// 都是熟悉的),运算符"=="也用来测 ...
- iOS 进阶 第十五天(0417)
0417 创建UICollectionViewCell的Xib方法如下图 枚举定义导航跳转方式 js跳转到网页指定锚点 如下图所示:
- C++ STL find
find 函数,复杂度O(n) 涉及一些 泛型编程 #include <iostream> #include <string.h> #include <string> ...
- 【Construct Binary Tree from Inorder and Postorder Traversal】cpp
题目: Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume ...
- OS X 使用技巧——访问所有的键盘功能
苹果笔记本电脑和苹果的无线键盘只有一个Delete键,可以删除光标前面的字. 按住Fn键再按Delete键就能删除光标后面的字符. 按住Fn键会把上下方向键的效果变成Page Up / Page Do ...
- appium 调试问题--UiAutomator died while responding to command
运行程序问题: 解决办法: 手机系统版本较低导致,我是V4.2.2,在android 4.3 系统上运行正常 代码如下: #coding=utf-8 ''' 作者:xxx 功能:测试计算器基本功能 注 ...
- 【ContestHunter】【弱省胡策】【Round3】(C)
容斥原理+Fib Orz HE的神犇们 蒟蒻只能改出来第三题……实在太弱 官方题解:http://pan.baidu.com/s/1o6MdtQq fib的神奇性质……还有解密a[i]的过程……这里就 ...