码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5323Solve this interesting problem 暴搜

时间:2015-07-29 14:08:57      阅读:93      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!