中级农民
- 积分
- 278
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2011-2-2
- 最后登录
- 1970-1-1
|
本帖最后由 writecoffee1 于 2012-6-14 00:16 编辑
https://github.com/writecoffee/career_cup_iteration/blob/improved/5.7.cpp
//////////////////////////////////////////////////////////////////////////////////////
// GIST
// 1. since the array starts from zero, in the LSB, originally bit-0 amount should
// be at least equivalent to that of bit-1
// 2. based on the above statement, every time 'imbalence' occurs (i.e. when one of
// the 0-bits was removed, bit-1 amount would be bigger or equals to that of the
// bit-0; on the opposite, when one of the 1-bits was removed, bit-0 amount just
// naturally bigger than that of the bit-1) we can get the missing bit and
// eliminate half the array elements where the opposite bit exists
// 3. recurse step-2 from LSB to MSB repeatedly
// (4.) when array becomes empty, fill up 0-bit in the front of the binary result
//
// TIME_COMPLEXITY
// at each level, we need (N-1) / 2^lev operations, 'width' levels combined is
// 2N, namely O(N)
////////////////////////////////////////////////////////////////////////////////////
|
|