zoukankan      html  css  js  c++  java
  • BST POJ

    Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. Now you are given some queries as "What are the minimum and maximum numbers in the subtree whose root node is X?" Please try to find answers for there queries. 

    Input

    In the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X (1 <= X <= 2 31 - 1).

    Output

    There are N lines in total, the i-th of which contains the answer for the i-th query.

    Sample Input

    2
    8
    10
    

    Sample Output

    1 15
    9 11

    https://blog.csdn.net/fengkuangdewoniudada/article/details/69660755
    规律请看这篇博客

    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <cmath>
    #include <algorithm>
    #include <set>
    #include <iostream>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #define pi acos(-1.0)
    #define eps 1e-6
    #define fi first
    #define se second
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define bug         printf("******
    ")
    #define mem(a,b)    memset(a,b,sizeof(a))
    #define fuck(x)     cout<<"["<<x<<"]"<<endl
    #define f(a)        a*a
    #define sf(n)       scanf("%d", &n)
    #define sff(a,b)    scanf("%d %d", &a, &b)
    #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    #define pf          printf
    #define FRE(i,a,b)  for(i = a; i <= b; i++)
    #define FREE(i,a,b) for(i = a; i >= b; i--)
    #define FRL(i,a,b)  for(i = a; i < b; i++)
    #define FRLL(i,a,b) for(i = a; i > b; i--)
    #define FIN freopen("DATA.txt","r",stdin)
    #define lowbit(x)   x&-x
    #pragma comment (linker,"/STACK:102400000,102400000")
    
    using namespace std;
    typedef long long LL;
    
    int main() {
        int t, n;
        scanf("%d", &t);
        while(t--) {
            scanf("%d", &n);
            int k=lowbit(n);
            printf("%d %d
    ",n-k+1,n+k-1);
        }
        return 0;
    }
  • 相关阅读:
    一、NHibernate 使用配置与实现简单查询
    NHibernate学习步骤
    sql2008转成2005的解决办法
    二、使用NHibernate对数据库实现增、删、改、查操作
    FusionCharts 点击事件 新页面
    [分享]NHibernate视频教程
    FusionCharts Free使用文档教程第五章FusionCharts Free使用dataXML加载数据
    职业规划
    网页生成pdf文件
    FusionCharts Free使用文档教程第四章FusionCharts Free使用JavaScript加载图形
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9415740.html
Copyright © 2011-2022 走看看