看了wys的论文,感觉获得了不少新姿势
这里总结一下
#includeusing namespace std;typedef unsigned int u32;inline u32 read_bit(u32 x, int pos){ return (x >> pos)&1;}inline u32 set_bit(u32 x, int pos){ return x | (1u << pos); }inline u32 clear_bit(u32 x, int pos){ return x & ~(1u << pos);}int cnt_table[1 << 16];void count_pre(){ cnt_table[0] = 0; for(int i = 0; i < 1<<16; i++){ cnt_table[i] = cnt_table[i >> 1] + (i & 1); }}inline int count(u32 x){ return cnt_table[x >> 16] + cnt_table[x & 65535u];}inline int count_trailing_zeros(u32 x){ int ret = 0; if(!(x & 65535u)) x >>= 16, ret |= 16; if(!(x & 255u)) x >>= 8, ret |= 8; if(!(x & 15u)) x >>= 4, ret |= 4; if(!(x & 3u)) x >>= 2, ret |= 2; if(!(x & 1u)) x >>= 1, ret |= 1; return ret + !x;}int clz_table[1 << 16];void clz_pre(){ clz_table[0] = 16; for(int i = 1; i < 1 << 16; i++){ clz_table[i] = clz_table[i >> 1] - 1; }}inline int count_learding_zero(u32 x){ return x >> 16 ? clz_table[x >> 16] : 16 + clz_table[x & 65535u];}inline u32 lowbit(u32 x){ return x & -x;}//ö¾Ù×Ó¼¯void subS(int S){ for(int i = S; i; i = (i-1)&S){ //do_something(i); }}int main() { return 0; }