标签:binary index tree algorithm
#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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:binary index tree algorithm
原文地址:http://blog.csdn.net/zone_programming/article/details/47782887