pid=5323" target="_blank" style="">链接

Solve this interesting problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 511    Accepted Submission(s): 114

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
 
Source
 

题意:
给定区间[l,r]
用线段树的递归建树方式build(1, n)
问最小的n是多少,使得build(1,n) 中能直接建出区间[l,r]
思路:
注意一下范围,然后推算一下就能发现这个区间距离根节点的距离不超过10
所以从底向上搜就好了

代码

HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜的更多相关文章

  1. hdu5323 Solve this interesting problem(爆搜)

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

  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. DFS+剪枝 HDOJ 5323 Solve this interesting problem

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

  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. hdu 5031 Lines 爆搜

    事实上嘞,这个线能够仅仅延伸一端 然后嘞,爆搜一次就能够 最后嘞,600-800ms过 本弱就是弱啊.你来打我呀-- #include<iostream> #include<cstr ...

  9. hdu 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

随机推荐

  1. Microsoft SQL Server学习(四)--约束

    SQLServer - 约束 主要是为了保证数据库中的数据一致性.有效性.准确性, 从而提高了数据库中数据的正确性 一.约束的分类 在SQLserver中,约束分三种不同类型 1.实体约束 实提约束是 ...

  2. C/C++ char*、char[]

    一.本质区别 char* s是一个保存字符串首地址的指针变量,char a[]是许多连续的内存单元,单元中的元素为char类型.之所以用char *能达到char []的效果,还是字符串的本质,即给你 ...

  3. 【Linux】Tomcat安装及端口配置

    安装环境 :Linux(CentOS 64位) 安装软件 : apache-tomcat-9.0.20.tar.gz(下载地址http://tomcat.apache.org/) 一:JDK安装配置 ...

  4. 02网页<body></body>常用标记及属性

    网页<body></body>常用标记及属性 <body></body>标记表示的是在整个浏览器内容框架中显示的部分. text属性用于控制HTML文档 ...

  5. 我的第一次"闭包"应用

    结论: 闭包可以当作强类型语言如C++.Java的全局变量使用,非常巧妙 需求: ssm项目,使用pagehelper分页,在写前一页.后一页.第一页.最后一页等页面跳转时,遇到了问题,如果查询全部的 ...

  6. Laravel5.5 综合使用

    使用 Laravel5.5 开发一个自动交割的项目,把使用到的开源扩展包及特性整理起来,以供后续使用. 一.安装IDE提示工具 Laravel IDE Helper 是一个极其好用的代码提示及补全工具 ...

  7. Python基础之变量进阶

    变量的引用 变量和数据都是保存在内存中的: 在python中函数的参数传递以及返回值都是靠引用传递的. 函数引用的概念 在python中 变量和数据时分开存储的: 数据保存在内存中的一个位置: 变量保 ...

  8. 【Python实践-8】和为S的两个数字

    (剑指offer)输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 思路:选定第一个数字,然后遍历后面的数字求和并与S比 ...

  9. vue子组件向父组件传递参数的基本方式

    子组件: this.$emit('transferUrl', this.picUrl) 父组件: 引入子组件<pics @transferUrl="gettransferUrl&quo ...

  10. 洛谷 3870 [TJOI2009]开关

    [题解] 线段树基础题.对于每个修改操作把相应区间的sum改为区间长度-sum即可. #include<cstdio> #include<algorithm> #include ...