【原创】二切贪食蛇(BCS)
来源:互联网 发布:ps mac触摸板无法缩放 编辑:程序博客网 时间:2024/06/05 13:27
特别版权声明:此数据结构为bzy原创数据结构,转载请先联系作者,QQ:1143710044.
二切贪食蛇(BCS)
二切贪食蛇(Binary-Cuts-Snake),是一种蛇(树)形数据结构,先来看看它的各种作用与复杂度.(-_-)
- 插入元素:
O(64) - 删除元素:
O(64) - 查找元素是否存在
O(64) - 查找元素对应存储数据
O(64) - 查找元素在数据结构中的排列位置O(64)
- 查询元素总量O(1)
- 查询最小的元素O(64)
- 空间复杂度O(2n - 64n)
再看代码:
class binary_cut_snake{ typedef unsigned long long _ull; private : struct node{ int value; int degree[2]; _ull up,down; node *left; node *right; node (_ull _up,_ull _down){ up = _up ; down = _down ; left = NULL ; right = NULL ; degree[0] = degree[1] = 0 ; } }; static const _ull _maxull = 18446744073709551615ull; node *first; public : binary_cut_snake() : first(new node(0,_maxull)){} void push(int num,int value){ _ull _lf=0,_ri = _maxull; node **now = &first; _ull _noi = 9223372036854775808ull; bool _isnimi = ! include (num) ; while(_lf ^ _ri){ _ull _mid = (_lf + _ri)>>1; if(_noi & num){ if((*now)->right == NULL){ (*now)->right = new node(_mid + 1 ,_ri); } (*now)->degree[1] += _isnimi ; now = & ((*now)->right); _lf = _mid + 1; (*now) ->down= _lf ; (*now) -> up = _ri ; }else{ if((*now)->left == NULL){ (*now)->left = new node(_lf ,_mid); } (*now)->degree[0] += _isnimi ; now = & ((*now)->left); _ri = _mid ; (*now) ->down= _lf ; (*now) -> up = _ri ; } _noi >>= 1 ; if(_lf == _ri)(*now) -> value = value ; } } int get(int num){ _ull _noi = 9223372036854775808ull; node **now = &first; while(_noi){ if(*now==NULL)return 0; if(_noi & num){ now = & ((*now)->right) ; }else{ now = & ((*now)->left) ; } _noi >>= 1; } return (*now) ->value; } int search_fore(_ull num){ _ull _noi = 9223372036854775808ull; node **now = &first; int _ans = 0; while(_noi){ if(*now==NULL)return _ans; if(_noi & num){ _ans += (*now)->degree[0]; now = & ((*now)->right); }else{ now = & ((*now)->left); } _noi >>=1 ; } return _ans + 1; } bool include(_ull num){ _ull _noi = 9223372036854775808ull; node **now = &first; while(_noi){ if(*now==NULL)return 0; if(_noi & num){ now = & ((*now)->right); }else{ now = & ((*now)->left); } _noi >>=1 ; } return 1; } int count(){ return first->degree[0]+first->degree[1]; } void del(int num){ _ull _noi = 9223372036854775808ull; node **now = &first; while(_noi){ if(*now==NULL)return; if(_noi & num){ (*now) -> degree[1] --; if((*now) ->degree[1] + (*now) -> degree[0] ==0){ (*now)=NULL; return ; } now = & ((*now) -> right); }else{ (*now) -> degree[0] --; if((*now) ->degree[0] + (*now) -> degree[1] ==0){ (*now)=NULL; return ; } now = & ((*now) -> left); } _noi >>=1; } return ; } _ull least(){ _ull _noi = 9223372036854775808ull; _ull _ans = 0; node **now = &first; while(_noi){ if(*now==NULL)return 0; if((*now)->degree[0]){ now = &((*now)->left); _ans <<= 1; }else{ now = &((*now)->right); _ans <<= 1; _ans = _ans | 1; } _noi >>= 1; } return _ans; }};
以上就是BCS的全部代码.
功能:
我们可以拿它代替map.push(),get()函数即可满足此功能,
还可以代替堆Heap.用least(),del(),push()函数即可。
还可以代替set,include()函数可以判重
还可以代替二分查找树(binary-sort-tree)Search-Fore()函数可以直接查找元素位置
还可以兼顾线段树部分功能.
此文章与此数据结构版权归bzy所有。
阅读全文
1 0
- 【原创】二切贪食蛇(BCS)
- 二截贪食蛇(BCS Plus)
- as贪食蛇小游戏(二)
- [视频]Android开发视频之贪食蛇案例(二)
- Unity3D 贪食蛇小游戏Demo[3D版](二)
- 贪食蛇(文本模式)
- SharePoint使用BCS开发你第一个应用程序(二)
- SharePoint 2010 BCS - 简单实例(二)外部列表创建
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- Cocos2dx 3.0 过渡篇(二十四)死不了的贪食蛇(重力版)
- Cocos2dx 3.0 过渡篇(二十五)死不了的贪食蛇(触摸版)
- 【Android Studio】分类整理res/Layouts中的布局文件(创建子目录)
- SVN使用教程和注意事项
- vue向子组件传递参数的两种方式
- Linux 目录结构及文件基本操作
- 复制整张表或复制表结构
- 【原创】二切贪食蛇(BCS)
- 策略路由PBR
- jq文件后缀选择器
- python —— 一门简单优美的语言
- linux使用yum更新下载时报错PYCURL ERROR 56
- css测试选择器汇总
- random.nextInt()与Math.random()基础用法
- 感想篇:6.2)如何构建自己的技术博客
- Spring10种常见异常解决方法