hdu5323Solve this interesting problem 暴搜

//给一对数[l,r]
//问找出最小的n使得线段树的根节点的左右范围是[0,n],且
//该线段树中有左右范围为[l,r]的节点
//由于l/(r-l+1)≤2015
//可以直接暴力搜索以[l,r]为节点的其父亲节点的情况
//然后比较其最小值
#include
#include
#include
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) ;
    }
}

你可能感兴趣的:(暴力)