二截贪食蛇(BCS Plus)
来源:互联网 发布:淘宝店铺域名怎么设置 编辑:程序博客网 时间:2024/06/12 08:37
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 ;
value = 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 = 1 ;
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; } if((*now)==NULL)return 0; 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 ; } if((*now)==NULL)return _ans; 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 ; } if(*now==NULL)return 0; return 1; } _ull fore(int num){ int _rank = search_fore(num); return search_index(_rank-include(num)); } _ull next(int num){ int _rank = search_fore(num); int g=get(num); return search_index(_rank+(g?g:1)); } _ull search_index(int index){ _ull _noi = 9223372036854775808ull; node **now = &first; while(_noi){ if(*now==NULL)return 0; if(index>(*now)->degree[0]){ index -= (*now)->degree[0]; now = & ((*now)->right); }else{ now = & ((*now)->left); } _noi >>=1 ; } if(*now==NULL)return 0; return (*now)->down; } 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; } if(*now==NULL)return; (*now)->value -- ; if((*now)->value==0)*now=NULL; 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; } if(*now==NULL)return 0; return _ans; }
};
- 二截贪食蛇(BCS Plus)
- 【原创】二切贪食蛇(BCS)
- as贪食蛇小游戏(二)
- [视频]Android开发视频之贪食蛇案例(二)
- Unity3D 贪食蛇小游戏Demo[3D版](二)
- 贪食蛇(文本模式)
- SharePoint使用BCS开发你第一个应用程序(二)
- SharePoint 2010 BCS - 简单实例(二)外部列表创建
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- 贪食蛇
- Cocos2dx 3.0 过渡篇(二十四)死不了的贪食蛇(重力版)
- Cocos2dx 3.0 过渡篇(二十五)死不了的贪食蛇(触摸版)
- android模拟器 获取蓝牙的状态值(开/关)
- java基础中几种最常见的迭代
- ImageLoader 的应用
- OpenGL_8 光照和键盘
- VIN/车架号OCR识别:快速占领汽车后市场数据入口
- 二截贪食蛇(BCS Plus)
- error char hashcode
- Python字符串处理函数记录
- 通过一个故事来看java nio
- java中接口
- python生成器
- 二维list 无法转为二维的numpy.array?
- gitlab使用总结
- Maven和Gradle对比