POJ 2309 BST 二叉树性质 位运算
来源:互联网 发布:免费手机小号软件 编辑:程序博客网 时间:2024/05/16 12:21
BST
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8155 Accepted: 4920
Description
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 <= 231 - 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
Source
POJ Monthly,Minkerui
《数据结构编程实验》P244页。解法很巧妙。
#include <iostream>using namespace std;int lowbit(int x){return x & -x;} int main(){int n,x;cin>>n;while (n--){cin>>x;cout<<x-lowbit(x)+1<<' '<<x+lowbit(x)-1<<endl;}return 0;}
kdwycz的网站: http://kdwycz.com/
kdwyz的刷题空间:http://blog.csdn.net/kdwycz
0 0
- POJ 2309 BST 二叉树性质 位运算
- POJ 2309 BST 位运算应用
- POJ 2309 BST(二叉搜索树)
- URAL 1088|Ilya Murometz|位运算|满二叉树的性质|LCA
- 位运算的性质
- 位运算的性质
- 位运算的性质
- POJ 2418 Hardwood Species(二叉搜索树BST)
- 二叉树的性质
- 二叉树数学性质
- 二叉树的性质
- 二叉树的性质
- 二叉树性质
- 二叉树的性质
- 二叉树的性质
- 二叉树的性质
- 二叉树性质总结
- 二叉树重要性质
- HDU 1226 搜索
- hdu 1829 A Bug's Life
- hdu1002
- 字符设备驱动之led灯的控制实验
- C++编程问题--glibc detected *** ./a.out: munmap_chunk(): invalid pointer: xxxxxx
- POJ 2309 BST 二叉树性质 位运算
- AbstractList.equals(Object o)
- [C\C++基础知识] main函数的参数argc和argv
- action里面获取session以及获取设置session的属性
- C++篇 特破private
- hdu 1503 Advanced Fruits(最长公共子序列变形)
- 题目1214:丑数
- 从Linux内核代码中学习获得结构体成员偏移量的方法
- int main(int argc,char* argv[])详解