博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
KMP
阅读量:6982 次
发布时间:2019-06-27

本文共 2526 字,大约阅读时间需要 8 分钟。

最近重新学习了一下KMP算法,然后重新做了自己的模板。

题目链接:

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 #define MAXN 10010 7 #define MAXM 1000010 8 char str1[MAXN]; 9 char str2[MAXM];10 int Next[MAXN];11 12 int len1,len2;13 14 void Get_Next(){15 int j=0,k=-1;16 Next[0]=-1;17 while(j
View Code

 题目链接:

1 #include
2 #include
3 #include
4 using namespace std; 5 #define MAXN 100100 6 int Next_a[MAXN]; 7 int Next_b[MAXN]; 8 char str1[MAXN]; 9 char str2[MAXN];10 11 void Get_Next(char str[],int Next[]){12 Next[0]=-1;13 int j=0,k=-1,len=strlen(str);14 while(j
View Code

 题目链接:

思路: 输出次数就是字符串的循环结,然后求最大最小的位置就是字符串的最小表示法了。

cxlove大神讲的很清楚:

1 #include
2 #include
3 #include
4 using namespace std; 5 #define MAXN 1000100 6 int Next[MAXN]; 7 char str[MAXN]; 8 9 void Get_Next(){10 Next[0]=-1;11 int len=strlen(str),j=0,k=-1;12 while(j
0?(p2=p2+k+1):(p1=p1+k+1);44 if(p1==p2)p2++;45 k=0;46 }47 }48 return p1
View Code

 题目链接:

1 #include
2 #include
3 #include
4 using namespace std; 5 #define MAXN 50050 6 int Next[MAXN]; 7 char str1[MAXN]; 8 char str2[MAXN]; 9 10 void Get_Next(){11 Next[0]=-1;12 int len=strlen(str1);13 int j=0,k=-1;14 while(j
0)i=len2-len1;//这点很重要,要防止出现这种rie mmriemm情况;28 while(i
View Code

 题目链接:

题意:orz..题意都理解了半天!!!

说的是给你一个26个字母表,每个字母对应的位置的字母就是明文所对应的密文,然后再给你一个字符串,字符串前部分为密文,后部分为前部分密文所对应的明文。而且密文和明文不会嵌套在一起。但是明文只显示了一部分,现在需要你补充所缺少的明文。就是先取字符串的前一半,将其转成明文后与后一半去匹配,最后返回模式串中指针的位置pos,然后原字符串中len-pos的位置就是明文开始的位置了。

1 #include
2 #include
3 #include
4 using namespace std; 5 #define MAXN 100010 6 int Next[MAXN]; 7 char s[33],ss[33]; 8 char str[MAXN]; 9 char str1[MAXN];10 11 void Get_Next(){12 Next[0]=-1;13 int len=strlen(str1),j=0,k=-1;14 while(j
View Code

 题目链接:

思路:这题的关键点就是要知道字符串循环节的求法(Next数组的运用),然后注意就是要取模了。

1 #include
2 #include
3 #include
4 using namespace std; 5 #define MAXN 100100 6 int Next[MAXN]; 7 char str[MAXN]; 8 int len; 9 10 void Get_Next(){11 Next[0]=-1;12 int j=0,k=-1;13 while(j
View Code

 

转载地址:http://kvvpl.baihongyu.com/

你可能感兴趣的文章
用SQL语句添加删除修改字段
查看>>
查md5或者sha1值
查看>>
spring MVC(2)--注解Hello World
查看>>
httpclient 小例子编写
查看>>
我的友情链接
查看>>
修改了系统时间后,myeclipse 和tomcat下的代码不同步了
查看>>
IDEA 一直不停的scanning files to index解决办法
查看>>
运维少年系列 python and cisco (1)
查看>>
c#时间转换
查看>>
调度器Quartz的简述与使用总结
查看>>
smokeping 安装
查看>>
Linux下安装oracle数据库步骤
查看>>
yum 不小心删除后安装
查看>>
vim 使用
查看>>
为敏感信息设置安全屏障
查看>>
进程与线程
查看>>
经典SQL
查看>>
维基百科:主流移动设备的屏幕参数
查看>>
使用CGContext画线操作小记
查看>>
mysql fabric安装使用测试
查看>>