#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
/**
* @author johnsondu
* @time 2015-8-19 16:37
* @type Binary Index tree
* @key try to understand how to retrieve
* the last bit of a number which is 1.
* @url http://poj.org/problem?id=2309
*/
int main()
{
int tcase;
int q;
scanf("%d", &tcase);
while(tcase --) {
scanf("%d", &q);
int lowbit = q & (-q);
printf("%d %d\n", q-lowbit+1, q+lowbit-1);
}
return 0;
}
【树状数组】POJ 2309 BST
最新推荐文章于 2021-11-03 17:18:44 发布
本文详细阐述了在给定整数中找到最后一个为1的位的算法实现,通过使用位操作技巧,该方法有效地揭示了数字的二进制表示中最右的1位。适合对计算机科学基础感兴趣的读者深入学习。

3039

被折叠的 条评论
为什么被折叠?



