POJ 2309 BST
来源:互联网 发布:免费安全软件排行 编辑:程序博客网 时间:2024/06/06 12:35
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
2
8
10
Sample Output
1 15
9 11
找规律即可。
#include<iostream>#include<cstdio>using namespace std;int q;int main(){ scanf("%d",&q); while(q--) { int x,y; scanf("%d",&x); y=x&(-x); printf("%d %d\n",x-y+1,x+y-1); } return 0;}
- poj 2309 BST (^ ^)
- POJ 2309 BST
- poj 2309 BST
- POJ 2309 BST
- POJ 2309 BST
- BST - POJ 2309 水题
- POJ 2309 BST
- poj 2309 BST(lowbit)
- POJ 2309 BST
- poj 2309 BST
- POJ 2309:BST lowbit
- poj 2309 BST
- POJ 2309 BST
- Poj 2309 BST
- POJ 2309 BST
- POJ 2309 BST
- POJ 2309 BST
- poj 2309 BST(水)
- 148. Sort List (python)
- java例题学习:猜数字游戏
- 利用Android studio修改包名
- go语言笔记
- 【51Nod1277】字符串中的最大值
- POJ 2309 BST
- Spring学习第七天:Bean的作用域
- [bzoj3252]攻略
- Kafka的broker替补替换测试
- Intent总结
- 328. Odd Even Linked List (python)
- day14 python css 漂浮的学习
- Codeforces-379C-New Year Ratings Change
- Android SQL 数据库使用(1)