Poj 2309 BST (mathematical problem)

Source: Internet
Author: User

BST
Time limit:1000 ms   Memory limit:65536 K
Total submissions:8440   Accepted:5093

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


========================================================== ======================================
This is the use of the lowbit function. It is easy to understand the lowbit function.
 
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <algorithm> # include <math. h> # define Maxx 1000int lowbit (int x) {return X & (-x);} int main () {int I, j, n, m; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & M ); int CAS = lowbit (m); printf ("% d \ n", M-cas + 1, m + cas-1);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.