POJ_2309_BST(位运算)
2014-03-10 19:09
357 查看
题型:数据结构
题意:对于二叉搜索树,给出一个节点,求出该节点的最左子孙和最右子孙的节点号。
分析:
运用树状数组里所使用的压位运算,可以轻松的算出节点所管辖的范围,即:
[n-(n&(-n)),n+(n&(-n))]
代码:
题意:对于二叉搜索树,给出一个节点,求出该节点的最左子孙和最右子孙的节点号。
分析:
运用树状数组里所使用的压位运算,可以轻松的算出节点所管辖的范围,即:
[n-(n&(-n)),n+(n&(-n))]
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; int Lowbit(int t) { return t & -t; } int main(){ int t,n; while(~scanf("%d",&t)){ while(t--){ scanf("%d",&n); int x = Lowbit(n) - 1; printf("%d %d\n",n-x,n+x); } } return 0; }
相关文章推荐
- POJ 2309 BST 【位运算】
- POJ 2309 BST 二叉树性质 位运算
- POJ 2309 BST 位运算应用
- BST - POJ 2309 水题
- (二叉搜索树10.1.1)POJ 2309 BST(求以x为根的满二叉搜索树的最小节点编号和最大节点编号)
- POJ 2309:BST lowbit
- POJ 2309 BST
- POJ 2309 BST(二叉搜索树)
- POJ 2309:BST lowbit
- POJ 2309 BST 树状数组基本操作
- poj2309——BST
- POJ 2309 BST(二叉搜索树)
- POJ 2309 BST
- Poj 2309 BST
- POJ 2309 BST(二叉搜索树)
- POJ 2309 BST(树状数组)
- POJ 2309 BST
- poj 2309 BST(lowbit)
- POJ 2309 BST
- poj 2309 BST