![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM KMP
桑榆207
在最终的结果到来之前,任何肯定会赢之类的话都是虚无缥缈的。
展开
-
扩展KMP题目总结
问题定义:给定两个字符串S和T(长度分别为n和m),下标从0开始,定义extend[i]等于S[i]...S[n-1]与T的最长相同前缀的长度,求出所有的extend[i]。显然,如果在S的某个位置i有extend[i]等于m,则可知在S中找到了匹配串T,并且匹配的首位置是i。模板#include <iostream>#include <string>...原创 2019-10-17 12:38:14 · 286 阅读 · 0 评论 -
HDU1385Period
http://acm.hdu.edu.cn/showproblem.php?pid=1358 Problem Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we w...原创 2018-12-17 11:22:57 · 106 阅读 · 3 评论 -
HUST - 1010KMP最小循环节性质
There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then, ...原创 2018-12-17 23:57:14 · 152 阅读 · 0 评论 -
POJ3080Blue Jeans KMP||模拟
http://poj.org/problem?id=3080DescriptionThe Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contr...原创 2019-01-15 08:54:01 · 118 阅读 · 0 评论 -
next数组求所有可能的循环节长度
For each prefix with length P of a given string S,ifS[i]=S[i+P] for i in [0..SIZE(S)-p-1],then the prefix is a “period” of S. We want to all the periodic prefixs.InputInput contains multiple c...原创 2019-02-27 20:25:27 · 228 阅读 · 0 评论 -
HDU 1686 Oulipo KMP求一个串在另一个串中出现的次数
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais tout s’...原创 2019-02-27 20:27:52 · 184 阅读 · 0 评论 -
POJ 1961 next数组求所有存在循环节的前缀长度
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ...原创 2019-02-27 20:37:23 · 251 阅读 · 0 评论 -
HDOJ3374 String Problem next数组+最小最大表示法
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings:String RankSKYLONG 1KYLONGS 2YLONGSK 3...原创 2019-02-27 20:52:32 · 133 阅读 · 0 评论 -
关于next数组的一个例题
It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example: s: "abab...原创 2019-02-26 16:14:33 · 1114 阅读 · 0 评论 -
next数组与最短循环节
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 ...原创 2019-02-26 16:44:10 · 228 阅读 · 0 评论 -
next数组
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-...原创 2019-02-26 21:59:42 · 580 阅读 · 0 评论 -
next数组 + 最小最大表示
Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings: String Rank SKYLONG 1 KYLONGS 2 YLONGSK 3 ...原创 2019-02-27 09:14:03 · 191 阅读 · 0 评论 -
CF--Compress Words--KMP匹配
E. Compress Wordstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmugae has a sentence consisting ofnnwords. He want to compres...原创 2019-08-12 15:16:06 · 612 阅读 · 0 评论 -
KMP+MANACHER题目总结
给出两个串S T,A操作S,B操作T。A先手,两人必须选择一种操作:翻转 23000->32 、 /10。S包含T了A胜利。思路:先将T串末尾的0去掉,然后用T去匹配S和S的反串。#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h&...原创 2019-10-07 20:28:30 · 204 阅读 · 0 评论 -
HDU3746Cyclic Nacklace 利用next数组补成至少两个循环节
http://acm.hdu.edu.cn/showproblem.php?pid=3746CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left...原创 2018-12-17 10:34:04 · 122 阅读 · 0 评论 -
HDU1686Oulipo KMP返回串出现的次数
http://acm.hdu.edu.cn/showproblem.php?pid=1686 The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote ...原创 2018-12-16 23:32:17 · 144 阅读 · 0 评论 -
POJ 1961 Period (KMP)
利用next数组求解#include <cstdio>#include <cstring>using namespace std;const int maxn = 1000000 + 10;char str[maxn];int next[maxn];int len;int cas;int n; void getNext(){ int i ...原创 2018-12-10 17:16:42 · 89 阅读 · 0 评论 -
很详细的KMP算法1
KMP算法应该是每一本《数据结构》书都会讲的,算是知名度最高的算法之一了,但很可惜,我大二那年压根就没看懂过~~~之后也在很多地方也都经常看到讲解KMP算法的文章,看久了好像也知道是怎么一回事,但总感觉有些地方自己还是没有完全懂明白。这两天花了点时间总结一下,有点小体会,我希望可以通过我自己的语言来把这个算法的一些细节梳理清楚,也算是考验一下自己有真正理解这个算法。 什么是KMP算法:...转载 2018-12-01 11:26:14 · 244 阅读 · 0 评论 -
KMP统计子串在母串中出现次数
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;char T[1000000+100],P[10000+100];int f[10000+100];in...原创 2018-12-01 12:21:47 · 1459 阅读 · 0 评论 -
POJ 3080 Blue Jeans(KMP:最长连续公共子序列)
把模板写上,改一下,改的方法我觉得需要积累然后是从第一个串中枚举子串,判断二分找出最长的然后等长再判断字典序#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace ...原创 2018-12-05 10:45:42 · 169 阅读 · 0 评论 -
HUST 1010 The Minimum Length (kmp求最小循环节)
题目描述There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. T...原创 2018-12-08 21:39:43 · 131 阅读 · 0 评论 -
UVA 1328 Period(KMP:最短循环节的有无及长度)
要明确判断条件充分利用next数组就行#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;const int MAXN=1000000+10;int f[MA...原创 2018-12-08 22:35:24 · 101 阅读 · 0 评论 -
POJ 2406 Power Strings(KMP:找串循环节)
http://poj.org/problem?id=2406此题是找到循环节的个数判断方法是len%(len-next[len])==0才输出len/(len-next[len])否则输出1#include<bits/stdc++.h>using namespace std;char st[1000100];int next[1001000];void get...原创 2018-12-08 22:52:23 · 84 阅读 · 0 评论 -
HDU 2087 剪花布条 KMP(判断不重叠区间加以判断)在看题中逐渐理解kmp...
http://acm.hdu.edu.cn/showproblem.php?pid=2087#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int nexts...原创 2018-12-06 21:56:59 · 98 阅读 · 0 评论 -
HDU2203亲和串 把目标串复制一倍
http://acm.hdu.edu.cn/showproblem.php?pid=2203也就是判断模式串能否在目标串复制一倍后被包含,转化一下再利用kmp#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath...原创 2018-12-06 22:26:41 · 127 阅读 · 0 评论 -
HDU1867 A + B for you again KMP
http://acm.hdu.edu.cn/showproblem.php?pid=1867#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;const int...原创 2018-12-06 23:49:59 · 131 阅读 · 0 评论 -
前后缀匹配问题kmp
首先A和B合并他们一定是首尾重叠相连,要求合并后字典序最小,所以当合并后串长度一样时,我们要把A或B中字典序小的放在前面。 然后计算A的后缀和B的前缀匹配长度为len1,计算A的前缀和B的后缀匹配长度为len2。 如果len1大,那么就把A放前面。如果len2大,那么就把B放前面。这样才保证了长度最小啊这个题return的位置不同于判断子串问题,这个是获取匹配...原创 2018-12-06 23:53:46 · 709 阅读 · 0 评论 -
HDU 3746 Cyclic Nacklace(KMP:补齐循环节)
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about ho...原创 2018-12-09 23:32:52 · 138 阅读 · 0 评论 -
HDU2594 Simpsons’ Hidden Talents 前缀与后缀转化成用s1去匹配s2
http://acm.hdu.edu.cn/showproblem.php?pid=2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15076 ...原创 2018-12-10 10:23:38 · 133 阅读 · 0 评论 -
HDU1711KMP模板题返回匹配位置
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K ...原创 2018-12-16 08:57:41 · 247 阅读 · 0 评论 -
Kmp找子串第一次出现位置
<span style="font-size:18px;">#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespace std;const int MAXN=10000原创 2018-12-04 23:59:22 · 235 阅读 · 0 评论