转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Solve this interesting problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1731    Accepted Submission(s): 519

Problem Description
Have you learned something about segment tree? If not, don’t worry, I will explain it for you.
Segment Tree is a kind of binary tree, it can be defined as this:
- For each node u in Segment Tree, u has two values: Lu and Ru.
- If Lu=Ru, u is a leaf node. 
- If Lu≠Ru, u has two children x and y,with Lx=Lu,Rx=⌊Lu+Ru2⌋,Ly=⌊Lu+Ru2⌋+1,Ry=Ru.
Here is an example of segment tree to do range query of sum.

Given two integers L and R, Your task is to find the minimum non-negative n satisfy that: A Segment Tree with root node's value Lroot=0 and Rroot=ncontains a node u with Lu=L and Ru=R.

 



Input
The input consists of several test cases. 
Each test case contains two integers L and R, as described above.
0≤L≤R≤109
LR−L+1≤2015
 



Output
For each test, output one line contains one integer. If there is no such n, just output -1.
 



Sample Input
6 7
10 13
10 11
 



Sample Output
7
-1
12

比较隐晦的指出了爆搜的最大深度一定不会超过11层,所以,复杂度就是4^11次方,然后加一点可行性的剪枝之类,就能AC了

 //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
ll ans = ;
void dfs(ll l,ll r){
if(l<)return;
if(r<l)return;
if(l==){
if(ans==-)ans = r;
else ans = min(ans,r);
return;
}
if(r>=ans&&ans!=-)return;
if((r-l+)>(l))return;
dfs(l-(r-l)-,r);
dfs(l,r+(r-l));
dfs(l-(r-l)-,r);
dfs(l,r+(r-l)+);
return;
}
int main()
{
ios::sync_with_stdio(false);
ll l,r;
while(cin>>l>>r){
ans = -;
dfs(l,r);
cout<<ans<<endl;
}
return ;
}

hdu5323 Solve this interesting problem(爆搜)的更多相关文章

  1. HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜

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

  2. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  3. 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 ...

  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. 2019年牛客多校第二场 F题Partition problem 爆搜

    题目链接 传送门 题意 总共有\(2n\)个人,任意两个人之间会有一个竞争值\(w_{ij}\),现在要你将其平分成两堆,使得\(\sum\limits_{i=1,i\in\mathbb{A}}^{n ...

  6. 多校赛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 ...

  7. HDU 4403 A very hard Aoshu problem(dfs爆搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...

  8. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  9. poj1077 Eight【爆搜+Hash(脸题-_-b)】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

随机推荐

  1. javascript学习教程之---如何从一个tab切换到banner幻灯片的转换

    一个简单的tab切换代码: <!doctype html> <html> <head> <meta charset="utf-8"> ...

  2. CSS3控制元素排列

    需求: 将改变为. 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  3. Python新手学习基础之函数-全局变量和局部变量

    全局变量和局部变量 我们通常把定义在函数外的变量成为全局变量,定义在函数内的变量称为局部变量,顾名思义,全局变量的作用域是整个代码段,局部变量的作用域就只是在它所属的代码段,变量只在它的作用域里有效. ...

  4. ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题

    ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题     如图红色为scrollview的背景色,在scrollview上加了图片之后,总会有向下的偏移 设置conten ...

  5. Lintcode--005(最长公共子序列)

    Given two strings, find the longest common subsequence (LCS).     最长公共子序列 Your code should return th ...

  6. 解压和生成 system.img&data.img ( ext4格式)

    另一篇文章讲述了如何解压和生成system.img, 那是针对yaffs2格式的文件系统镜像. 目前越来越多的Android手机放弃了nand, 更多采用了emmc为内部存储设备. 以emmc为存储设 ...

  7. Keil的可重定位段

    对于一个大的文件,为了便于管理,一个好的办法时把一个大文件分为若干个小文件,每个小文件包含一部分相关的功能,这样功能将显得很整洁,而且移植到其它工程的时候也很方便,把文件copy过去即可. 对于汇编, ...

  8. SmartBusinessDevFramework架构设计-2:结构图示

    架构设计一览图 下图表示了本架构的设计草稿. 接下来  ,我们将逐步细述,各个模块之间的松散耦合关系. 核心的实现原理.敬请关注.

  9. 简要介绍如何集成Vitamio安卓版SDK

    1.下载VitamioBundle的最新稳定,这里下载的是最新版4.2.2. 2.解压缩后,导入 Vitamio 库工程(即vitamio)和Demo工程(即vitamio--sample)到 Ecl ...

  10. shell中的IFS详解

    在bash中IFS是内部的域分隔符,manual中对其的叙述如下:IFS The Internal Field Separator that is used for word splitting af ...