I’m suddenly interested in blogging a little more actively. Let’s see how long this interest lasts. On a personal note, god save me if my life is gonna be a series of disjoint passions.

I knew of the implementation of considering all the subsets of a set using bitmasks – suppose that the superset contains n elements. The number of its subsets is N=2^n.
for(i=0; i<N; i++)
for(j=0; j<n; j++) if((i>j)&1) { jth bit of i is set; consider it as “jth element of n elements is chosen” and do things; }
Tautology in SPOJ is solvable using just this, if you knew how to evaluate a prefix expression.

What I wanted to mention, however, is that the function __builtin_popcount(unsigned int x) returns the number of bits set in x. It is a built-in function in GCC. Another thing I came across today and wasn’t aware of till now -
__FILE__ is a macro for the filename of the program,
__LINE__ for the current line number,
__DATE__ for the date as a string,
__TIME__ for the current time as a string.

Post a Comment

*
*