码迷,mamicode.com
首页 > 编程语言 > 详细

【树状数组】POJ 2309 BST

时间:2015-08-19 20:48:40      阅读:121      评论:0      收藏:0      [点我收藏+]

标签: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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

【树状数组】POJ 2309 BST

标签:binary index tree   algorithm   

原文地址:http://blog.csdn.net/zone_programming/article/details/47782887

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!