2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 422 Accepted Submission(s): 98
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
10 13
10 11
-1
12
它的上一个节点有(2*l-2-r,r),(2*l-1-r,r),(l,2*r-l+1),(l,2*r - l)四种情况,直接搜索,加上几个特殊判断即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
ll maxn = 0x3f3f3f3f;
ll ma; void dfs(ll l,ll r)
{
if(l == 0)
{
ma = min(r,ma);
return;
}
if(l > r)
return ;
if(r >= 1e18)
return ;
if(r - l + 1 > l)
return ;
if(l == r)
{
ma = r;
return ;
}
dfs(2*l-2-r,r);
dfs(2*l-1-r,r);
dfs(l,2*r-l+1);
dfs(l,2*r - l);
return ;
} int main()
{
ll a,b;
//freopen("8.txt","r",stdin);
while(~scanf("%I64d%I64d",&a,&b))
{
ma = maxn;
dfs(a,b); if(ma == maxn)
printf("-1\n");
else
printf("%I64d\n",ma);
}
return 0;
}
2015 多校联赛 ——HDU5323(搜索)的更多相关文章
- 2015 多校联赛 ——HDU5305(搜索)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5348(搜索)
Problem Description As we all kown, MZL hates the endless loop deeply, and he commands you to solve ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5335(Walk out)
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- 结对开发五--对一千个数long型的一维数组求最大子数组的和
一.设计思想 我们根据第一个实验,再让他自动生成1000个随机long型数.大致思想和实验一一样,自己已埋入炸弹. 二.实验代码 package com.minirisoft; import java ...
- MySQL 服务安装及命令使用
MySQL 服务安装及命令使用 课程来源说明 本节实验后续至第17节实验为本课程的进阶篇,都基于 MySQL 官方参考手册制作,并根据实验楼环境进行测试调整改编.在此感谢 MySQL 的开发者,官方文 ...
- mysql基础篇 - SELECT 语句详解
基础篇 - SELECT 语句详解 SELECT语句详解 一.实验简介 SQL 中最常用的 SELECT 语句,用来在表中选取数据,本节实验中将通过一系列的动手操作详细学习 SELEC ...
- nyoj 还是回文
还是回文 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描述 判断回文串很简单,把字符串变成回文串也不难.现在我们增加点难度,给出一串字符(全部是小写字母),添加或删除一个字符, ...
- Python脚本自动提取和替换代码中的中文
# -*- coding: utf-8 -*- import os import os.path import re import sys reload(sys) sys.setdefaultenco ...
- 腾讯云服务器上安装phstudy和lnmp
phpstudy的安装:wget -c http://lamp.phpstudy.net/phpstudy.bin chmod +x phpstudy.bin #权限设置./phpstudy.bin ...
- Java 持久化操作之 --io流与序列化
1)File类操作文件的属性 1.File类的常用方法 1. 文件的绝对完整路径:getAbsolutePath() 文件名:getName() 文件相对路径:getPath() 文件的上一级目录:g ...
- JavaScript 轮播图实例
HTML代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...
- C++ 排列最优解算法思想
枚举全排列 #include <iostream> #include <cstring> #include <string> using namespace std ...
- python多进程--------linux系统中python的os.fork()方法
linux下python 创建子进程的原理: os.fork()方法 的原理 为了实现并发.多任务,我们可以在主程序种开启一个进程或者线程.在类unix操作系统当中(非windows),可以用pyth ...