hdu5323Solve this interesting problem 暴搜

//给一对数[l,r]
//问找出最小的n使得线段树的根节点的左右范围是[0,n],且
//该线段树中有左右范围为[l,r]的节点
//由于l/(r-l+1)≤2015
//可以直接暴力搜索以[l,r]为节点的其父亲节点的情况
//然后比较其最小值
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std ;
typedef long long     ll ;
const __int64 inf =  1e18;
ll ans ;
ll L , R ;
void dfs(ll l , ll r)
{
    if(r >= ans)return ;
    if(l < 0)return ;
    if(l == 0){ans = r ;return ;}
    if(r - l + 1 > l)return ;
    dfs(2*(l-1) - r , r) ;
    dfs(2*(l-1) - r + 1 , r);
    dfs(l , 2*r - l) ;
    dfs(l , 2*r - l + 1) ;
}
int main()
{
    ll l , r ;
    while(~scanf("%I64d%I64d" ,&L , &R))
    {
        ans = inf;
        dfs(L , R) ;
        if(ans == inf)puts("-1");
        else
        printf("%I64d\n" , ans) ;
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-22 12:59:07

hdu5323Solve this interesting problem 暴搜的相关文章

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): 511    Accepted Submission(s): 114 Problem Description Have you learned something about segment tree? If not, d

hdu3699 A hard Aoshu Problem 暴搜

http://acm.hdu.edu.cn/showproblem.php?pid=3699 A hard Aoshu Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 968    Accepted Submission(s): 490 Problem Description Math Olympiad is calle

[ACM] hdu 4403 A very hard Aoshu problem (DFS暴搜数字)

A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a pro

HDU 5012 bfs暴搜

Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 243    Accepted Submission(s): 135 Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number wa

2014牡丹江网络预选赛F题(隐式图BFS暴搜)zoj3814

Sawtooth Puzzle Time Limit: 10 Seconds      Memory Limit: 65536 KB Recently, you found an interesting game called Sawtooth Puzzle. This is a single-player game played on a grid with 3 x 3 cells. Each cell contains a part of an image. Besides, each ed

codeforces 339C Xenia and Weights(dp或暴搜)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts

hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1110    Accepted Submission(s): 280 Problem Description Terrorists put some mines in a crowded square recently. The police evacuate all peo

hdu 4848 Wow! Such Conquering! (暴搜+强剪枝)

Wow! Such Conquering! Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description There are n Doge Planets in the Doge Space. The conqueror of Doge Space

HDU4403(暴搜)

A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4403 Description Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary m