博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BST POJ - 2309 思维题
阅读量:5155 次
发布时间:2019-06-13

本文共 1772 字,大约阅读时间需要 5 分钟。

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

2810

Sample Output

1 159 11 https://blog.csdn.net/fengkuangdewoniudada/article/details/69660755 规律请看这篇博客
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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("******\n")#define mem(a,b) memset(a,b,sizeof(a))#define fuck(x) cout<<"["<
<<"]"<
= 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",n-k+1,n+k-1); } return 0;}

 

转载于:https://www.cnblogs.com/qldabiaoge/p/9415740.html

你可能感兴趣的文章
矩阵快速幂---BestCoder Round#8 1002
查看>>
js兼容公用方法
查看>>
如何将应用完美迁移至Android P版本
查看>>
【转】清空mysql一个库中的所有表的数据
查看>>
基于wxPython的python代码统计工具
查看>>
淘宝JAVA中间件Diamond详解(一)---简介&快速使用
查看>>
Hadoop HBase概念学习系列之HBase里的宽表设计概念(表设计)(二十七)
查看>>
Kettle学习系列之Kettle能做什么?(三)
查看>>
Day03:Selenium,BeautifulSoup4
查看>>
awk变量
查看>>
mysql_对于DQL 的简单举例
查看>>
35. Search Insert Position(C++)
查看>>
[毕业生的商业软件开发之路]C#异常处理
查看>>
一些php文件函数
查看>>
有关快速幂取模
查看>>
Linux运维必备工具
查看>>
字符串的查找删除
查看>>
NOI2018垫底记
查看>>
快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0
查看>>
Codeforces Round #277 (Div. 2)
查看>>