![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
KMP
AKone123456
这个作者很懒,什么都没留下…
展开
-
51NOD1277 字符串中的最大值----------------------思维(kmp)
解析:#include<bits/stdc++.h>using namespace std;const int N=1e6+1000;typedef long long ll;int f[N];ll dp[N];char s[N];int n;void init(){ f[0]=-1; for(int i=2,j=0;i<=n;i++) { while(j&&s[i]!=s[j+1]) j=f[j]; if(s[i]==..原创 2020-09-16 14:20:30 · 92 阅读 · 0 评论 -
周期--------------------------------思维(kmp+最小循环节)
解析:kmp+最小循环节最小循环节 :n-next[n]循环次数:n/(n-next[n])本题只要一位一位去匹配计算即可#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;const int N=1e6+10;int f[N];int n,k;char s[N];void init(){ for..原创 2020-05-16 11:32:32 · 141 阅读 · 0 评论 -
问题 L: 【KMP】Radio Transmission
第二天叫醒我的不是闹钟,是梦想! 题目描述给你一个字符串,它是由某个字符串不断自我连接形成的。但是这个字符串是不确定的,现在只想知道它的最短长度是多少。输入第一行给出字符串的长度L,第二行给出一个字符串,全由小写字母组成。输出输出最短的长度。样例输入 Copy8cabcabca样例输出 Copy3提示我们可以利用abc不断自我连接得到abcabcabc,读入的cabca...原创 2019-11-16 19:05:29 · 173 阅读 · 0 评论 -
D - Cyclic Nacklace HDU - 3746--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 th...原创 2019-11-16 16:47:57 · 137 阅读 · 0 评论 -
B - Power Strings POJ - 2406--KMP求最小循环节
第二天叫醒我的不是闹钟,是梦想! Given two strings a and b we define ab to be their concatenation. For example, if a = “abc” and b = “def” then ab = “abcdef”. If we think of concatenation as multiplication, exponen...原创 2019-11-16 15:20:43 · 108 阅读 · 0 评论 -
A - Period UVA - 1328---KMP最小循环节
第二天叫醒我的不是闹钟,是梦想! For each prefix of a given string S with N characters (each character has an ASCII code between 97 and126, inclusive), we want to know whether the prefix is a periodic string. That...原创 2019-11-16 14:37:53 · 119 阅读 · 0 评论 -
B - Simpsons’ Hidden Talents HDU - 2594--KMP前缀与后缀
第二天叫醒我的不是闹钟,是梦想! Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.Marge: Yeah, what is it?Homer: Take me for example. I want to find out if I have a t...原创 2019-11-16 12:51:02 · 114 阅读 · 0 评论 -
A - Seek the Name, Seek the Fame POJ - 2752---KMP前缀与后缀
第二天叫醒我的不是闹钟,是梦想! The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at th...原创 2019-11-16 11:19:40 · 145 阅读 · 0 评论 -
扩展kmp
第二天叫醒我的不是闹钟,是梦想! 题目描述有两个字符串aa,bb,要求输出bb与aa的每一个后缀的最长公共前缀输入格式两行,分别为两个字符串aa,bb输出格式共两行第一行有lenb个数,为b的next数组(特别地,next_{1}next1 为lenb)第二行有lena个数,即答案输入输出样例输入 #1复制aaaabaaaaaaa输出 #1复制5 4 3 2 ...原创 2019-11-16 10:12:56 · 95 阅读 · 0 评论 -
G - 亲和串 HDU - 2203---KMP模板题
第二天叫醒我的不是闹钟,是梦想! 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就...原创 2019-11-14 22:52:53 · 124 阅读 · 0 评论 -
F - 剪花布条 HDU - 2087-----KMP模板
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。Output输出能从花...原创 2019-11-14 18:54:46 · 191 阅读 · 0 评论 -
C - Count the string HDU - 3336----KMP模板
第二天叫醒我的不是闹钟,是梦想! 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...原创 2019-11-14 18:21:30 · 169 阅读 · 0 评论 -
B - Number Sequence HDU - 1711----KMP模板
第二天叫醒我的不是闹钟,是梦想! 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 which make a[K] = b...原创 2019-11-12 13:24:59 · 125 阅读 · 0 评论 -
A - Oulipo POJ - 3461---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 no...原创 2019-11-12 13:02:47 · 167 阅读 · 0 评论