首页 > 其他 > 详细

hdu5323Solve this interesting problem 暴搜

时间:2015-07-29 14:06:40      阅读:234      评论:0      收藏:0      [点我收藏+]
//给一对数[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) ;
    }
}

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

hdu5323Solve this interesting problem 暴搜

原文:http://blog.csdn.net/cq_pf/article/details/47125777

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!