POJ 2309:BST lowbit】的更多相关文章

BST Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9140   Accepted: 5580 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 c…
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1的边不一定的树,然后给出问题:询问区间和 或者 节点值更新. HDU 3887: 题意:和POJ 3321的题意差不多,只不过对每个节点询问不包含该节点的区间和 思路:今天才学了下才知道有DFS序这种东西,加上树状数组处理一下区间和 和 节点更新. DFS序大概就是我们在DFS遍历一棵树的时候,在进…
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 3669 Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Sciss…
题意是给你一个满二叉树,给一个数字,求以这个数为根的树中最大值和最小值. 理解树状数组中的lowbit的用法. 说这个之前我先说个叫lowbit的东西,lowbit(k)就是把k的二进制的高位1全部清空,只留下最低位的1,比如10的二进制是1010,则lowbit(k)=lowbit(1010)=0010(2进制),介于这个lowbit在下面会经常用到,这里给一个非常方便的实现方式,比较普遍的方法lowbit(k)=k&-k,这是位运算,我们知道一个数加一个负号是把这个数的二进制取反+1,如-1…
假设领悟了树阵lowbit,这个问题很简单,底部是奇数,使用lowbit(x)寻找x父亲,然后x父亲-1是的最大数量 至于lowbit问题是如何计算,寻找x父亲,事实上x+2^x二进制结束0的数量. #include<iostream> #include<stdio.h> using namespace std; typedef long long ll; ll lowbit(int x){ return x&(-x); } int main(){ ll n,a; cin&…
BST Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8565   Accepted: 5202 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 c…
思路:除以2^k,找到商为奇数的位置,k为层数,有2^(k+1)-1个节点 这里直接用位运算,x & -x 就求出 2^k 了. #include<iostream> using namespace std; long lowbit(long x) { return x & -x; } int main() { long n,x; cin>>n; while(n--) { cin>>x; cout<<x-lowbit(x)+1<<…
BST Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8657   Accepted: 5277 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 c…
题意:给出一棵二分搜索树,再给一个节点编号n,求以这个节点为根节点的子树叶子节点的最大值与最小值. 首先求n所在的层数,他的层数就是他的因子中2的个数(规律). n的左右各有num=2^i-1个数.最小值是n-num,最大值是n+num #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <queue> using nam…
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 leve…