POJ2309 BST

作者: Rememberautumn 分类: 算法与数据结构 发布时间: 2014-10-25 09:41 阅读: 1,790
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. 
POJ2309 BST

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

Sample Output



原文请访问:http://xiaoshig.sinaapp.com/?p=197

This article is automatically posted by WP-AutoPost : WordPress自动采集发布插件
解决乱码问题,WP-AutoPost

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注