题意:重复子串次数 思路:kmp #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 1000005 int next[MaxSize]; void GetNext(char t[]){//求next数组 int j,k,len; j=; k=-; next[]=-; len=strlen(t); while(j<len){ ||t…
题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K 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 = "abcdef". If we thi…
传送门 http://poj.org/problem?id=2406 题目就是求循环了几次. 记得如果每循环输出为1.... #include<cstdio> #include<cstring> const int MAXN=1000000+10; char P[MAXN]; int f[MAXN]; int n,m; void getFail() { int i,j; f[0]=f[1]=0; for(i=1;i<n;i++) { j=f[i]; while(j &…
题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 1000005 char str[MaxSize]; int next2[MaxSize]; void GetNext(char t[]){ int j,k,len; j=; k=-; next2[]=-; len=strl…
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27003   Accepted: 11311 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = &q…
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 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 = "abcdef…
题意:给一个字符串,求该串最多由多少个相同的子串相接而成. 思路:只要做过poj 1961之后,这道题就很简单了.poj 1961 详细题解传送门. 假设字符串的长度为len,如果 len % (len - next[len])不为0,说明该字符串不能由其他更短的字符串反复相接而成,结果输出1,否则答案为len / (len - next[len]). #include<stdio.h> #include<string.h> #define maxn 1000010 char s[…
点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted: 11454 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 =…
本题是计算一个字符串能完整分成多少一模一样的子字符串. 原来是使用KMP的next数组计算出来的,一直都认为是能够利用next数组的.可是自己想了非常久没能这么简洁地总结出来,也仅仅能查查他人代码才恍然大悟,原来能够这么简单地区求一个周期字符串的最小周期的. 有某些大牛建议说不应该參考代码或者解题报告,可是这些大牛却没有给出更加有效的学习方法,比方不懂KMP.难倒不应该去看?要自己想出KMP来吗?我看不太可能有哪位大牛能够直接自己"又一次创造出KMP"来吧. 好吧.不说"创造…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 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 = "…