hdu Lowest Bit

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1196

大水题   lowbit   的应用    (可以取出一个数二进制中的最后一个1。树状数组常用,Lowbit(x)=x&-x。 )

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <ctype.h>
 7 #include <iomanip>
 8 #include <queue>
 9 #include <stdlib.h>
10 using namespace std;
11 
12 int s[50005];
13 int t,n,m,p,i,j;
14 
15 int lowbit(int x)
16 {
17     return x&(-x);
18 }
19 
20 void add(int x, int d){
21     while (x <= n){
22         s[x] += d;
23         x += lowbit(x);
24     }
25 }
26 
27 int sum(int x){
28     int ans = 0;
29     while (x > 0){
30         ans += s[x];
31         x -= lowbit(x);
32     }
33     return ans;
34 }
35 
36 int main()
37 {
38     int A;
39     while(~scanf("%d",&A)){
40         if(A==0)
41             break;
42         int d=lowbit(A);
43         printf("%d
",d);
44     }
45 }
原文地址:https://www.cnblogs.com/wangmengmeng/p/4972690.html