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 ...
随机推荐
- python的小爬虫的基本写法
1.最基本的抓站 import urllib2 content = urllib2.urlopen('http://XXXX').read() 2.使用代理服务器 这在某些情况下比较有用,比如IP被封 ...
- database first表更新一个表会更新所有的model,包括添加验证代码,解决办法
因为model类是自动生成的,重新生成后会覆盖自己的修改.一个比较合理做法,就是用 partial class的方式来实现. 比如有一个Model类: Movie.那我们就可以添加一个局部类文件,局部 ...
- 用Sqlplus手动创建Oracle11g数据库
用Sqlplus手动创建Oracle数据库 刚开始学习Oracle数据库,菜鸟一个,使用sqlplus创建数据库遇到了很多问题,通过不断地百度,终于创建成功了.所以顺便把整个过程中犯的一些最低级的错误 ...
- P1119: [POI2009]SLO
这题预处理稍微动动脑,其实还是个裸的置换群=-=,没什么压力. ; var n,i,j,minx,tem,now,tmin,len:longint; cursum,sum:int64; pos,num ...
- Travis-CI的进一步使用
今天主要对.travis.yml文件和makefile进行进一步的了解: 1.在.travis.yml文件中添加了给linux系统中安装了cppunit库的语句,使能够持续集成写过的单元测试的代码.主 ...
- 动态生成C# Lambda表达式
转载:http://www.educity.cn/develop/1407905.html,并整理! 对于C# Lambda的理解我们在之前的文章中已经讲述过了,那么作为Delegate的进化使用,为 ...
- Entity Framework技术导游系列开篇与热身
在微软平台写程序有年头了,随着微软数据存取技术的持续演化,我在程序中先后使用过ODBC.DAO.ADO.ADO.NET.LINQ to SQL. Entity Framework这些技术. 近几年来, ...
- MyEclipse: Can't load IA 32-bit .dll on a AMD 64-bit platform
java.lang.UnsatisfiedLinkError: D:\Tomcat7\apache-tomcat-7.0.59\bin\tcnative-1.dll: Can't load IA 32 ...
- 一个包的net到gs流程
再来看看一个包走共享内存的流程 先来看看net进程这块如何处理的 {//用shareData这种类型封装刚才从无锁队列中取到的包 shareData sd; sd.channel_id = pkt.c ...
- [geeksforgeeks] Count the number of occurrences in a sorted array
Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...