STL.h
最近老是被系统的一些STL卡到飞起,然后就手打了一个STL.h 库函数还没有打完,以后打新的还会再更,大家也可以使用,顺便帮我找一下bug,然后我再改进!
template< typename RT >class queue
{
public:
RT sta[];
int l,r;
void clear(){l=r=;}
inline void push(RT x){sta[r++]=x;return ;}
inline void pop(){l++;return ;}
inline RT front(){return sta[l];}
inline bool empty(){return r==l;}
inline bool size(){return r!=l;}
};
template< typename RT >class stack
{
public:
RT sta[];
int topp;
void clear(){topp=;}
inline void push(RT x){sta[++topp]=x;return ;}
inline void pop(){topp--;return ;}
inline bool empty(){return topp==;}
inline bool size(){return topp;}
inline bool top(){return sta[topp];}
};
template< typename RT >class hash_table
{
public:
int mod;
inline void init(int x){mod=x;return ;}
int head[],vvt[],nxt[],tot;
RT ver[];
inline void insert(int x,RT ac)
{
int u=x%mod;
for(int i=head[u];i;i=nxt[i])
{
RT y=ver[i];
if(y==ac){vvt[i]++;return ;}
}
ver[++tot]=ac;
nxt[tot]=head[u];
head[u]=tot;
vvt[tot]++;
}
inline int query_times(int x,RT ac)
{
int u=x%mod;
for(int i=head[u];i;i=nxt[i])
{
RT y=ver[i];
if(y==ac)return vvt[i];
}
return ;
}
};
//////未完/////////
2019.9.23 UPDATE
更新了queue和stack的大小参数和一些骚操作!
hash_table 没有更新!
//#include<iostream>
//#include<cstdio>
//#include<cstdlib>
//#include<algorithm>
//using namespace std; //make by lsc; %%%stl
template<typename RT,int MAXN>
class stack
{
public:
RT sta[MAXN];int topp;
inline void clear(){topp=;return ;}
inline void init(){topp=;return ;}
inline void push(RT x){sta[++topp]=x;return ;}
inline int size(){return topp;}
inline bool empty(){return topp;}
inline int bottom(){if(topp==)return -(<<);else return sta[];}
inline int num(RT x){return sta[x];}
inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
/*
if struct sort please make function!
*/
};
template<typename RT,int MAXN>
class queue
{
public:
#define re register
RT sta[MAXN];
int fr,back;
inline void init(){fr=;back=;}
inline void push(re RT x){sta[++back]=x;return ;}
inline void pop(){fr++;return ;}
inline RT front(){return sta[fr];}
inline bool empty(){if(back>=fr)return ;else return ;}
inline bool size(){if(back<=fr)return ;else return ;}
inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
};
UPDATE 新版本!
/*
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
*/ //make by lsc; %%%stl
template<typename RT,int MAXN>
class stack
{
public:
RT sta[MAXN];int topp;
inline void clear(){topp=;return ;}
inline void init(){topp=;return ;}
inline void push(RT x){sta[++topp]=x;return ;}
inline int size(){return topp;}
inline bool empty(){return topp;}
inline int bottom(){if(topp==)return -(<<);else return sta[];}
inline int num(RT x){return sta[x];}
inline void pop(){topp--;if(topp<)topp=;return ;}
inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
/*
if struct sort please make function!
*/
};
template<typename RT,int MAXN>
class queue
{
public:
#define re register
RT sta[MAXN];
int fr,back;
inline void init(){fr=;back=;}
inline void push(re RT x){sta[++back]=x;return ;}
inline void pop(){fr++;return ;}
inline RT front(){return sta[fr];}
inline bool empty(){if(back>=fr)return ;else return ;}
inline bool size(){if(back<=fr)return ;else return ;}
inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
}; template<typename RT,int MAXN>
class priority_queue
{
public:
RT q[MAXN];int sz;
priority_queue(){sz=;}
inline void push(int x)
{
q[++sz]=x;
for(int i=sz,j=i>>;j;i=j,j>>=)
if(q[j]>q[i])swap(q[j],q[i]);
}
inline void pop()
{
q[]=q[sz--];
for(int i=,j=i<<;j<=sz;i=j,j<<=)
{
if((j|)<=sz&&q[j|]<q[j])j=j|;
if(q[i]>q[j])swap(q[i],q[j]);
else break;
}
}
inline RT top(){return q[];}
};
//UPDATE 2019.9.23 pair 未经过测试!
template<typename RT,typename RE>
class pair
{
public:
RT first;RE second;
pair(){first=,second=;}
inline void make_pair(RT a,RE b){first=a,second=b;return ;}
/*
THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!
*/
};
UPDATE 2019.9.26 整理了一下,但没有测试!
/*
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
*/ //make by lsc; %%%stl
template<typename RT,int MAXN>
class stack
{
public:
RT sta[MAXN];int topp;
inline void clear(){topp=;return ;}
inline void init(){topp=;return ;}
inline void push(RT x){sta[++topp]=x;return ;}
inline int size(){return topp;}
inline bool empty(){return topp;}
inline int bottom(){if(topp==)return -(<<);else return sta[];}
inline int num(RT x){return sta[x];}
inline void pop(){topp--;if(topp<)topp=;return ;}
inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
/*
if struct sort please make function!
*/
};
template<typename RT,int MAXN>
class queue
{
public:
#define re register
RT sta[MAXN];
int fr,back;
inline void init(){fr=;back=;}
inline void push(re RT x){sta[++back]=x;return ;}
inline void pop(){fr++;return ;}
inline RT front(){return sta[fr];}
inline bool empty(){if(back>=fr)return ;else return ;}
inline bool size(){if(back<=fr)return ;else return ;}
inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
}; template<typename RT,int MAXN>
class priority_queue
{
public:
RT q[MAXN];int sz;
priority_queue(){sz=;}
inline void push(int x)
{
q[++sz]=x;
for(int i=sz,j=i>>;j;i=j,j>>=)
if(q[j]>q[i])swap(q[j],q[i]);
}
inline void pop()
{
q[]=q[sz--];
for(int i=,j=i<<;j<=sz;i=j,j<<=)
{
if((j|)<=sz&&q[j|]<q[j])j=j|;
if(q[i]>q[j])swap(q[i],q[j]);
else break;
}
}
inline RT top(){return q[];}
}; //UPDATE 2019.9.23 pair 未经过测试!
template<typename RT,typename RE>
class pair
{
public:
RT first;RE second;
pair(){first=,second=;}
inline void make_pair(RT a,RE b){first=a,second=b;return ;}
/*
THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!
*/
}; template< typename RT >class hash_table
{
public:
int mod;
inline void init(int x){mod=x;return ;}
int head[],vvt[],nxt[],tot;
RT ver[];
inline void insert(int x,RT ac)
{
int u=x%mod;
for(int i=head[u];i;i=nxt[i])
{
RT y=ver[i];
if(y==ac){vvt[i]++;return ;}
}
ver[++tot]=ac;
nxt[tot]=head[u];
head[u]=tot;
vvt[tot]++;
}
inline int query_times(int x,RT ac)
{
int u=x%mod;
for(int i=head[u];i;i=nxt[i])
{
RT y=ver[i];
if(y==ac)return vvt[i];
}
return ;
}
};
//2019.9.26 UPDATE
//lower_bound but didn't test ,you can test it ,but not int exam!
//I dont't konw if it has bugs!
template<typename RT,typename RE>
RE lower_bound(RT *a,RE l,RE r)
{
while(l<r)
{
int mid=(l+r)>>;
if(a[mid]>=r)r=mid;
else l=mid+;
}
return l;
};
STL.h的更多相关文章
- 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?
在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 右键选择该文件.cpp格式的->属性->预编译头,→ 不使用预编译 ...
- STLtoSVG,and SVG to Bmp
先用这两个工具: Slic3R或者Skeinforge:这个两个工具的作用就是把STL文件切片为叠加的矢量图(SVG格式) 因为SVG是分层的,一层一层的把每层都转换成一张Bmp文件 听说ImageM ...
- C++客户端访问WebService VS2008
VS2008及之后的版本已经不支持使用C++开发WEBService服务了,如果要在VS上开发WEBService,需要使用C#开发语言. 一.gSOAP简介 gSOAP编译工具提供了一个基于SOAP ...
- ubuntu 16.04 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/a41adc1/,欢迎阅读! Interfacing C++ and Python with pybind11 on ubuntu ...
- windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10
本文首发于个人博客https://kezunlin.me/post/8b9c051d/,欢迎阅读! Interfacing C++ and Python with pybind11 on window ...
- VS2015 dlib编译 x64 Release .lib生成
VS2015 dlib编译 x64 Release >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Bui ...
- VS2015 dlib编译 x64 Debug .lib生成
VS2015 dlib编译 x64 Debug >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Checking Build S ...
- JMeter接口测试印象篇(win10)
参考博文1:https://www.cnblogs.com/suim1218/p/9257369.html 参考博文2:https://blog.csdn.net/u011541946/article ...
- 混合编程:如何用python11调用C++
摘要:在实际开发过程中,免不了涉及到混合编程,比如,对于python这种脚本语言,性能还是有限的,在一些对性能要求高的情景下面,还是需要使用c/c++来完成. 那怎样做呢?我们能使用pybind11作 ...
随机推荐
- mac下的环境变量
a. /etc/profile b. /etc/paths c. ~/.bash_profile d. ~/.bash_login e. ~/.profile f. ~/.bashrc 其中a和b是系 ...
- struts 2.3.28+spring 4.2.5.RELEASE+hibernate 5.1.0.Final整合maven构建项目基本配置
第一次写博客,主要也是记录给自己看的,可能很多比较熟的地方就没注释 用maven构建,ssh框架都是选用的最新的release版(感觉还是不要用beta),环境jdk1.8 tomcat8.0 mys ...
- Linux入门(服务)
LInux入门之 服务 服务介绍 常驻在内存中的程序,且可以提供一些系统或网络功能,那就是服务.比如: apache提供web服务 ftp提供文件下载上传服务 ssh提供了远程连接服务 防火墙提供了安 ...
- 用go语言爬取珍爱网 | 第一回
我们来用go语言爬取"珍爱网"用户信息. 首先分析到请求url为: http://www.zhenai.com/zhenghun 接下来用go请求该url,代码如下: packag ...
- tesseract 测试样例
该图片的链接为https://raw.githubusercontent.com/Python3WebSpider/TestTess/master/image.png,可以直接保存或下载. 首先用命令 ...
- session与cookie,django中间件
0819自我总结 一.session与cookie 1.django设置session request.session['name'] = username request.session['age' ...
- Python_生成随机验证码
内置函数 chr() ord() 这两个内置函数是用来对十进制(十六进制也可以)与ASCii之间进行转换 chr() : 将十进制转换成ASCii对应字母或符号 t_1 = chr(99) t_2 = ...
- Oracle11g安装与基本使用
目录 安装 修改用户密码 配置文件修改 使用PLSQL连接Oracle数据库 如何执行SQL 语句 本教程基于oracle11g和PLSQL进行 下载资源见百度网盘链接:https://pan.bai ...
- Ubuntu 搜狗输入法输入异常
电脑放置一段时间,不使用.过了一会,再使用 sogou 输入法的时候,发现,输入法不起作用了. 切花到用户目录 ~/.config 里面 rm -rf Sogou* 删除搜狗的配置文件,退出当前账户, ...
- opencv::模糊图像
Smooth/Blur 是图像处理中最简单和常用的操作之一,使用该操作的原因之一就为了给图像预处理时候减低噪声 使用Smooth/Blur操作其背后是数学的卷积计算,通常这些卷积算子计算都是线性操作, ...