自己YY一下可以发现answer = n - fail[ n ] ----------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ;…
kmp复健,答案是n-next[n] #include<iostream> #include<cstdio> using namespace std; const int N=1000005; int n,ne[N]; char s[N]; int main() { scanf("%d%s",&n,s+1); int j=0; for(int i=2;i<=n;i++) { while(s[j+1]!=s[i]&&j) j=ne[j…
题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如: a b a b a b next:-1 0 0 1 2 3 4 next[n]==4,代表着,前缀abab与后缀abab相等的最长长度,这说明,ab这两个字母为一个循环节,长度=n-next[n]; #include <iostream> #inc…
链接: https://vjudge.net/problem/HDU-1358#author=0 题意: 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…
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13790 Accepted Submission(s): 5738 Problem Description CC always becomes very depressed at the end of this month, he has check…
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 31111 Accepted: 12982 Description 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 = "…