随笔分类 -  模板

摘要://树状数组 //支持给某位置增加常数与查询前缀和 #include #include #include #include #include #include using namespace std; int n,a[1001],tree[1001];//tree树状数组 int lowbit(int x)//表示2^k k是二进制数x的末尾0个数 { return x&(-x); ... 阅读全文
posted @ 2018-07-08 17:25 radishえらい 阅读(98) 评论(0) 推荐(0)
摘要://双重Hash 可保证不重复 //空间较大 时间较慢 不易被卡 #include #include #include #include #include #include #define MOD1 233333339 #define MOD2 233333393 #define MOD3 233333939 #define base 233 #define ull unsigned long... 阅读全文
posted @ 2018-07-08 17:25 radishえらい 阅读(165) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include #define ll long long using namespace std; ll n,jdg[1000001],prime[1000001],phi[1000001],cnt,ans; int main() { scanf("%lld",&n); phi[1]=1;... 阅读全文
posted @ 2018-07-08 17:24 radishえらい 阅读(94) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std; int n,m,jdg[10000001],prime[10000001],cnt; int main() { cin>>n>>m; jdg[1]=1; for(int i=2;in) bre... 阅读全文
posted @ 2018-07-08 17:24 radishえらい 阅读(93) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std; int jdg[10000001],n,m; int main() { cin>>n>>m; jdg[1]=1; for(int i=2;i>a; if(jdg[a]==0) cout... 阅读全文
posted @ 2018-07-08 17:23 radishえらい 阅读(106) 评论(0) 推荐(0)
摘要://三分 //劣于二分 但可以解决某些二分无法解决的问题 //求函数顶点可用 #include #include #include #include #include #include #define eps 1e-7 using namespace std; int n; double l,r,a[14]; double get(double x) { double num=0; ... 阅读全文
posted @ 2018-07-08 17:22 radishえらい 阅读(310) 评论(0) 推荐(0)
摘要://卢卡斯定理 可求在模p意义下的组合数 //公式:C(x,y)=C(x/p,y/p)*C(x%p,y%p) (mod p) #include #include #include #include #include #include #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f ll T,... 阅读全文
posted @ 2018-07-08 17:21 radishえらい 阅读(180) 评论(0) 推荐(0)
摘要://KMP //求匹配子串 #include #include #include #include #include #include using namespace std; int lena,lenb,next[1000001];//next[a]存放在a长度的子字符串中前后缀相同最长的长度 char a[1000001],b[1000001]; void getnxt() { ... 阅读全文
posted @ 2018-07-08 17:21 radishえらい 阅读(106) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std; long long a,b,MOD,ans=1; int main() { scanf("%lld%lld%lld",&a,&b,&MOD); while(b) { if(b&1) a... 阅读全文
posted @ 2018-07-08 17:17 radishえらい 阅读(105) 评论(0) 推荐(0)
摘要://矩阵快速幂 //满足c[x][y]=∑(i=1,i #include #include #include #include #include #define ll long long #define MOD 1000000007 using namespace std; ll n,k; struct uio{ ll squ[101][101],n,m; }mat; uio mult... 阅读全文
posted @ 2018-07-08 17:17 radishえらい 阅读(121) 评论(0) 推荐(0)
摘要://Manacher //可求最长回文子串长度 #include #include #include #include #include #include #define ma 11000005 using namespace std; int n,ans,length[mamxr) { mxr=length[i]+i; ... 阅读全文
posted @ 2018-07-08 17:16 radishえらい 阅读(151) 评论(0) 推荐(0)
摘要://高斯消元 //可解n元一次方程 //消成左上到右下的对角线 精度相对于上三角损失更大 #include #include #include #include #include #include #define eps 1e-7 using namespace std; int n; double coe[101][101],num[101]; int main() { scan... 阅读全文
posted @ 2018-07-08 17:15 radishえらい 阅读(141) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include #include #include using namespace std; const int MAX_L=2005; //最大长度,可以修改 class bign { public: int len, s[MAX_L];//数的长度,记录数组 //构造函数 big... 阅读全文
posted @ 2018-07-08 17:13 radishえらい 阅读(120) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include using namespace std; int n,m,k,ans,cnt,head[1001],vis[1001],match[1001]; struct uio{ int next,to; }edge[1000001]; int add(int x,int y) { ... 阅读全文
posted @ 2018-07-08 17:11 radishえらい 阅读(132) 评论(0) 推荐(0)
摘要://二叉查找树 //特点:每个点左子树上的点都小于该点,右子树上的点都大于该点 //没有取值相同的点 任意点的左右子树均为二叉查找树 //中序遍历严格单调递增 #include #include #include #include #include #include using namespace std; struct uio{ int num,cnt,dfs;//num取值 ... 阅读全文
posted @ 2018-07-08 17:10 radishえらい 阅读(117) 评论(0) 推荐(0)
摘要://单调队列 //队列元素递增或递减 元素最多进队出队各一次 //应用:复杂度为o(n^2)的动态规划 可求最大最小值 #include #include #include #include #include #include using namespace std; int n,m,a[1000001]; struct uio{ int minum,micnt; }mi[1000... 阅读全文
posted @ 2018-07-08 17:09 radishえらい 阅读(133) 评论(0) 推荐(0)
摘要://大步小步算法 BSGS //对于式子 x^y=z mod p 已知x,z和p可求y //由于费马小定理 y的取值范围为[0,p-1] //利用分块思想 将y分为a*m+b m=sqrt(p-1) //其中x^b预处理存在Hash中 枚举a即可 #include #include #include #include #include #include #include #define... 阅读全文
posted @ 2018-07-08 17:08 radishえらい 阅读(248) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include #define ll long long using namespace std; ll n,p; void exgcd(ll a,ll b,ll &x,ll &y) { if(!b) { x=1;y=0; return; } ... 阅读全文
posted @ 2018-07-08 17:00 radishえらい 阅读(162) 评论(0) 推荐(0)
摘要:#include #include #include #define maxn 105 #define INF 0x3f3f3f3f using namespace std; int head[maxn],maxcost[maxn][maxn],map[maxn][maxn]; bool used[maxn][maxn];//m int n,m,t,cnt,x,y,z,vis[maxn],d... 阅读全文
posted @ 2018-07-08 17:00 radishえらい 阅读(105) 评论(0) 推荐(0)
摘要:#include #include #include #include #include #include #define ll long long using namespace std; ll n,p,a[3000001]; int main() { scanf("%lld%lld",&n,&p); a[1]=1; printf("%lld\n",a[1]); ... 阅读全文
posted @ 2018-07-08 16:59 radishえらい 阅读(146) 评论(0) 推荐(0)