常用模板
LoR_Zhong
·
·
个人记录
- 快读快写
inline int read(){
int num=0,op=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') op=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
num=(num<<3)+(num<<1)+(ch^48);
ch=getchar();
}
return num*op;
}
inline void write(int num){
if(num<0){
putchar('-');
num=-num;
}
if(num>9) write(num/10);
putchar(num%10+'0');
}
- 二叉树
struct Tree{
int value;
char No;
Tree *Tleft,*Tright;
void Pre_order(){
cout<<this->No;
if(this->Tleft) this->Tleft->Pre_order();
if(this->Tright) this->Tright->Pre_order();
}
void In_order(){
if(this->Tleft) this->Tleft->In_order();
cout<<this->No;
if(this->Tright) this->Tright->In_order();
}
void Post_order(){
if(this->Tleft) this->Tleft->Post_order();
if(this->Tright) this->Tright->Post_order();
cout<<this->No;
}
};
- 快速幂
inline int qpow(int a,int n) {
int re=1;
while(n) {
if(n&1) re*=a;
n>>=1;
a*=a;
}
return re;
}