实时求一段0、1序列1的比例
来源:互联网 发布:今日目标软件怎么样 编辑:程序博客网 时间:2024/05/22 14:02
#define MIN(a,b) ((a) < (b) ? (a) : (b))#define FLAG_BUFF_LEN_BYTE 125#define FLAG_BUFF_LEN_BIT ( FLAG_BUFF_LEN_BYTE * 8)#define LONG_SMOOTH_NUM 1000unsigned short short_count; ///< Number of shortsunsigned char buff[FLAG_BUFF_LEN_BYTE]; ///< The flag buff, save as bitint pre_count;int index_byte; ///< The index by byteunsigned int index_bit; ///< The index by bitfloat ratio_short_mean; ///< The short ratiofloat ratio_long_smooth; ///< The long ratioshort_count = 0;memset(buff, 0, sizeof(buff));pre_count = 0;index_byte = 0;index_bit = 1;ratio_short_mean = 0;ratio_long_smooth = 0;if (flag){ count += (1 - ((buff[index_byte] & (unsigned char)index_bit) != 0 ? 1 : 0)); // if bit is 0, plus 1;else do nothing buff[index_byte] |= index_bit; // flush new value}else{ count -= (1 - ((buff[index_byte] & (unsigned char)index_bit) == 0 ? 1 : 0)); // if bit is 1, minus 1;else do nothing buff[index_byte] &= (~index_bit); // flush new value}index_bit <<= 1;if (index_bit > 128){ index_bit = 1; index_byte = (index_byte + 1) % FLAG_BUFF_LEN_BYTE;}if (pre_count < 1073741824){ pre_count++;}ratio_short_mean = (float)short_count / MIN(pre_count, FLAG_BUFF_LEN_BIT);ratio_long_smooth = ((pre_count - 1) * ratio_long_smooth + flag) / MIN(pre_count, LONG_SMOOTH_NUM);
阅读全文
0 0
- 实时求一段0、1序列1的比例
- Excel查询序列所对应的值-vLoopup函数,求比例分子改变但分母不变
- 求二进制序列中1的个数
- uva 1619 单调 求一段序列和 和 其中最小值的乘积的最大值
- 一段求根号的代码
- 求一段JavaScript的注释!!
- 一段求平方根的代码
- 求空间节省比例的方法
- JAVA 求两个值的 比例!
- 写一段程序,求1+2*2+3*3+n*n的值 Java
- 设置Android的ProgressBar的实时进度及比例
- 求一个数的二进制序列中1的个数
- 序列求和,求1+2+3+.....+n的值
- 求{1,2,3}序列的全排列
- 一段序列化成JSON格式的代码
- 微软面试题--翻转数组中的一段,使0为1,1为0,求此数组中1的个数最多
- 求一段区间内素数的个数
- 求一段连续整数区间的和
- webrtc中的video rtp packet 接收组包过程
- 进程与线程
- jquery mobile无法修改textarea的高度
- 安装mysql报错:The action 'Install' for product 'MySQL Server 5.7.20' failed.
- 一个程序从源代码到可执行程序的过程
- 实时求一段0、1序列1的比例
- SSE指令集 c,c++程序代码优化
- SVN 流程管理
- Java学习心得之Object类
- sql去重
- Java中创建对象的5种方式
- leetcode 523. Continuous Subarray Sum
- 三天屠狗、三周灭师,DeepMind发布千年以来最强围棋选手“AlphaGo Zero” ‖ 论文+棋谱
- 设计师福利!Adobe发布Typekit,分分钟帮你找到想要的字体