Solve this interesting problem

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

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=n contains 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
 
解题:搜索
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
LL X,Y,ret;
void dfs(LL L,LL R) {
if(R >= ret || L < ) return;
if(L == ) {
ret = min(ret,R);
return;
}
if(R - L + > L) return;
dfs(*L - R - ,R);
dfs(*L - R - ,R);
dfs(L,*R - L);
dfs(L,*R - L + );
} int main() {
while(~scanf("%I64d%I64d",&X,&Y)) {
ret = INF;
dfs(X,Y);
printf("%I64d\n",ret == INF?-:ret);
}
return ;
}

2015 Multi-University Training Contest 3 hdu 5323 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 5 hdu 5349 MZL's simple problem

    MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  4. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  5. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  6. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  7. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  9. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. phpMyAdmin 高级功能尚未完全设置,部分功能未激活(转载)

    phpMyAdmin 高级功能尚未完全设置,部分功能未激活.请点击这里查看原因. 第一步: 使用Mysql管理员帐号通过phpmyadmin登陆,然后点击“导入”,然后点击“浏览”按钮,找到phpmy ...

  2. echarts如何更改表格主题颜色

    vue项目中,需要使用echarts时,需要根据UI设计图进行图标颜色修改 方法一: 1.在script中引入echarts以及主题样式: import echarts from 'echarts'; ...

  3. a.WHERE使用中单行子查询(适用于>,<,=,>=,<=等条件)

    a.单行子查询(适用于>,<,=,>=,<=等条件)    //查询工资最高的员工编号和员工名   select empno,ename   from emp   where ...

  4. tomcat使用及原理

    1,Tomcat作为Servlet容器的基本功能 2,Tomcat的组成结构 Tomcat本身由一列的可配置的组件构成,其中核心组件是Servlet容器组件,它是所有其他Tomcat组件的顶层容器.T ...

  5. 主流框架(SSH及SSM)配置文件的模板头文件

    SSH三大框架整合配置头文件模板如下: 一:Spring配置文件(beans.xml)模板:<beans    xmlns="http://www.springframework.or ...

  6. JavaCodeTra 36选7 彩票抽奖

    想写个小代码试试自己的运气.然并卵.并不能猜中 import java.util.Random; import java.util.Scanner; /** * */ /** * @author Ha ...

  7. POJ 1107

    水题一道,注意取模时不能为0 #include <iostream> #include <algorithm> #include <cstring> #includ ...

  8. [ReactVR] Start a Virtual Reality Project Using the React VR CLI

    We will learn how to set up a React VR project, run the development mode with hot reloading, and tak ...

  9. Oracle 后台进程介绍

    一 进程分类: 1.服务器进程(server process): 依据客户请求完毕工作.如接收和处理应用发送的SQL语句 2.后台进程(background process): 随数据库而启动,用于完 ...

  10. bzoj2734【HNOI2012】集合选数

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 831  Solved: 487 [Submit][Stat ...