hdu Lowest Bit

时间:2023-03-09 04:16:21
hdu  Lowest Bit

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

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

代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <iomanip>
#include <queue>
#include <stdlib.h>
using namespace std; int s[];
int t,n,m,p,i,j; int lowbit(int x)
{
return x&(-x);
} void add(int x, int d){
while (x <= n){
s[x] += d;
x += lowbit(x);
}
} int sum(int x){
int ans = ;
while (x > ){
ans += s[x];
x -= lowbit(x);
}
return ans;
} int main()
{
int A;
while(~scanf("%d",&A)){
if(A==)
break;
int d=lowbit(A);
printf("%d\n",d);
}
}