【树状数组】POJ 2309 BST

来源:互联网 发布:苹果vip解析软件 编辑:程序博客网 时间:2024/05/16 10:26
#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;}

0 0
原创粉丝点击