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 (Java/Others)
Total Submission(s): 1479 Accepted Submission(s): 423
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.
Each test case contains two integers L and R, as described above.
0≤L≤R≤109
LR−L+1≤2015
#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的更多相关文章
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
pid=5323" target="_blank" style="">链接 Solve this interesting problem Tim ...
- DFS+剪枝 HDOJ 5323 Solve this interesting problem
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...
- 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 ...
- 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 ...
- 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: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 使用python备份数据库并删除备份超过一定时长的文件
#!/usr/bin/env python #-*- coding: utf-8 -*- """ @Project:Py @author:sandu @Email: sa ...
- Python学习笔记(一):基本数据类型
在Python3种,有六种标准数据类型: 数字(Number) 字符串(String) 列表(List) 元组(Tuple) 集合(Set) 字典(Dictionary) 这六种数据类型中,数字类型和 ...
- VUE:条件渲染和列表渲染
条件渲染 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- C# .net IDE Rider入门
话说史上最强IDE Visual Studio 所向披靡数十载尚无敌手,现在Intellij带着统一IDE界的目标来挑战VS的霸主地位.了解Rider后发现,哎哟亮点多多,还不错哦! Rider是一款 ...
- jvm 虚拟机的组成部分
1.类加载子系统 :负责从文件系统或者网络中加载 Class 信息,加载的信息存放在 一块称之为方法区的内存空间 2.方法区:存放类信息,常量信息,常量池信息,包括字符串字面量和数字常量等 3.Jav ...
- openssl之EVP系列之10---EVP_Sign系列函数介绍
openssl之EVP系列之10---EVP_Sign系列函数介绍 ---依据openssl doc/crypto/EVP_SignInit.pod翻译 (作者:DragonKing, ...
- 应用Spring和Hibernate(C3P0数据池)写数据库交互项目
一.xml的配置文件(application.xml) <?xml version="1.0" encoding="UTF-8"?> <bea ...
- OC的动态继承编译机制
[问]为什么OC不能sizeof一个对象的大小或一个类的大小?和类结构相近的结构体却能够. [再问]为什么OC不能将对象声明到静态空间,如栈中?和类结构相近的结构体却能够. [答]由于OC的动态继承编 ...
- Java多线程之~~~线程安全容器的非堵塞容器
在并发编程中,会常常遇到使用容器.可是假设一个容器不是线程安全的.那么他在多线程的插入或者删除的过程 中就会出现各种问题.就是不同步的问题.所以JDK提供了线程安全的容器,他能保证容器在多线程的情况下 ...
- MySQL超级简明基本操作攻略,给自己看(一)
系统:Ubuntu 14.04 LTS 安装: apt-get install mysql //安装数据库 apt-get install mysql-workbench //安装图形界面 使用: 启 ...