zoukankan      html  css  js  c++  java
  • 我的模板

    I/O

    getchar 快读

    目前看来已经成了时代的眼泪。

    template<typename T>
    void Read(T &_x){
    	_x=0;int _f=1;
    	char ch=getchar();
    	while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();
    	while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();
    	_x*=_f;
    }
    template<typename T,typename... Args>
    void Read(T &_x,Args& ...others){
    	Read(_x);Read(others...);
    }
    

    数学

    快速幂

    template<typename T1=int,typename T2=long long>
    T1 Pow(T1 _base,T2 _pow,const T1 _mod){
    	T1 _res=1;
    	while(_pow){
    		if(_pow&1) _res=T2(_res)*_base%_mod;
    		_pow>>=1,_base=T2(_base)*_base%_mod;
    	}
    	return _res%_mod;
    }
    

    光速幂

    template<long long _V,typename T1=int,typename T2=long long>
    struct FastPower{
    	static const int _Size=sqrt(_V+.5)+1;
    	T1 _pow1[_Size],_pow2[_Size];
    	const T1 _Base,_Mod;
    	FastPower(T1 _base,T1 _mod):_Base(_base),_Mod(_mod){
    		_pow1[0]=_pow2[0]=1;
    		for(int _i=1;_i<_Size;++_i)
    			_pow1[_i]=T2(_pow1[_i-1])*_Base%_Mod;
    		T1 _temp=T2(_pow1[_Size-1])*_Base%_Mod;
    		for(int _i=1;_i<_Size;++_i)
    			_pow2[_i]=T2(_pow2[_i-1])*_temp%_Mod;
    	}
    	T1 operator()(long long _p){
    		return T2(_pow1[_p%_Size])*_pow2[_p/_Size]%_Mod;
    	}
    };
    

    (mathcal{O}(V+log mod){large -}mathcal{O}(1)) 组合数

    //requires Pow
    template<int Lim>
    struct Comb{
    	const int Mod;
    	long long fac[Lim+1],ifac[Lim+1];
    	Comb(int _mod):Mod(_mod){
    		fac[0]=1;
    		for(int _i=1;_i<=Lim;++_i) fac[_i]=fac[_i-1]*_i%Mod;
    		ifac[Lim]=Pow((int)fac[Lim],Mod-2,Mod);
    		for(int _i=Lim-1;_i>=0;--_i) ifac[_i]=ifac[_i+1]*(_i+1)%Mod;
    	}
    	ll C(ll n,ll m){
    		if(n<m) return 0;
    		return fac[n]*ifac[m]%Mod*ifac[n-m]%Mod;
    	}
    };
    
    Written by Alan_Zhao
  • 相关阅读:
    爬取阳光问政平台
    CrawlSpider爬取腾讯招聘信息
    LinkExtractor
    镜像源列表
    screen命令总结
    PHP解决中文乱码问题
    Linux查找大文件或目录
    CentOS6/7系列防火墙管理
    删除win10冗余的服务
    解决win10安装wireshark新版本,欢迎界面卡顿情况
  • 原文地址:https://www.cnblogs.com/alan-zhao-2007/p/my-templates.html
Copyright © 2011-2022 走看看