![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
*****模版******
mml5211314
这个作者很懒,什么都没留下…
展开
-
KMP中求解next值的模板
void Getp() { int i=0,j=-1; next[i]=j; while (i<len) { if (j==-1||str[i]==str[j]) { i++; j++; next[i]=j; } else j=next[j]; } } 由于KMP算法只预处理B串,因此这种算法很适合这样的问题:给定一个B串和一群不同的A串,问B原创 2015-08-07 18:06:42 · 482 阅读 · 0 评论 -
求最大公约数(gcd)
#include int gcd(int a,int b) { if(a<b) { int t=a; a=b; b=t; } if(b==0) { return a; } return gcd(b,a%b); } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) {原创 2015-08-06 18:06:26 · 328 阅读 · 0 评论 -
二分查找
int l=1,r=ls; int md; while (r>=l) { md=(r+l)/2; if (b[md]<a[i]) l=md+1; else原创 2015-08-06 18:08:56 · 210 阅读 · 0 评论 -
并查集之找祖先的模板
int find(int x) { if (x==per[x]) return x; return per[x]=find(per[x]); }//递归查找 int find(int x) { int r=x; while (r!=per[r]) r=per[r]; per[x]=r; return r; }// int find(int x) { int原创 2015-08-08 16:08:02 · 344 阅读 · 0 评论