poj 2406 Power Strings 后缀数组解法】的更多相关文章

连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们还是用后缀数组做一做,巩固后缀数组的能力. 对于一个串,如果能写出a^n这种形式,我们可以暴力枚举循环节长度L,那么后缀suffix(1)和suffix(1 + L)的LCP应该就是 lenstr - L.如果能满足,那就是,不能,就不是. 这题的话da算法还是超时,等我学了DC3再写上来. 其实这…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28859   Accepted: 12045 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 = "…
题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的等式之后就知道是求a的n次方,也就是说求所给字符串的最大循环次数,想一想. 如果可以求出所给字符串的最小循环节, 那么是不是就可以求出它的最大循环次数了.   这是肯定的. 因为循环节最小. 循环次数也就最大 #include<iostream> #include<cstring> #…
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************************ * Author :Running_Time * Created Time :2015-8-10 10:51:54 * File Name :POJ_2406.cpp ************************************************/ #incl…
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…
Power Strings 题意 给出一个字符串s,求s最多由几个相同的字符串重复而成(最小循环节的重复次数) 思路 之前学习KMP的时候做过. 我的思路是:枚举字符串的长度,对于当前长度k,判断\(lcp(1,k+1)>=k\),\(lcp(k+1,2k+1)>=k\),\(lcp(3k+1,4k+1)>=k\)....是否都成立 但这样复杂度有点高,就找了一下题解. 其实只需要判断\(lcp(1,k+1)\)是否是\(n-k\)就可以了. 具体原理如下图: 参考博客 对于\(lcp(…
题意:求最小循环节循环的次数. 题解:这个题其实可以直接用kmp去求最小循环节,然后在用总长度除以循环节.但是因为在练后缀数组,所以写的后缀数组版本.用倍增法会超时!!所以改用DC3法.对后缀数组还不是很理解,找了很多博客也没看懂到底有些数组到底记录的是啥,但他的实现过程很好理解,等我弄懂了再来给博客加注释吧. 先求出sa数组,height数组,rank数组(因为和c++库中某个东西重了所以写成rnk数组),数组一定要开3倍.接下来从小到大枚举循环节长度 i,如果长度i的子串刚好是重复了len/…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 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 = "…
Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少次得到. analyse: KMP之next数组的运用.裸的求最小循环节. Time complexity: O(N) Source code:  ;;      ;);      ) ;}/* */…
F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2406 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = &…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 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 = "…
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 = "…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 48139   Accepted: 20040 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 = "…
点击打开链接 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 =…
                                                                                                  Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38038   Accepted: 15740 Description Given two strings a and b we define a*b t…
Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37685   Accepted: 15590 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 = "…
题目链接 题意:连续重复子串.给定一个字符串 L,已知这个字符串是由某个字符串 S 重复 R 次而得到的(L = S^R ), 求 R 的最大值. 分析:枚举长度,判断条件是能被总长度整除且LCP (suffix (0), suffix (i)) = n - i,预处理出lcp,方法是,lcp[i] = min (height[rank[i]] to height[rank[0]]); DC3算法,C++提交才能AC. #include<cstdio> #include<cstring&…
题目: http://poj.org/problem?id=2406 跟1961差不多,题解就不写了,一开始理解错题了,导致WA一次. #include <stdio.h> #include <string.h> #include <algorithm> ]; ]; void kmp_init() { ; next[] = -; ; i < n; i++) { && s[j+] != s[i]) j = next[j]; ] == s[i]) j+…
题意:给一个字符串,求该串最多由多少个相同的子串相接而成. 思路:只要做过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[…
题目链接: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 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是求字符串的最小循环节. 以下内容转载于:http://bbezxcy.iteye.com/blog/1377787 --------------------------------------------------------------------------------------------…
题目链接: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…
http://poj.org/problem?id=2406 [题意] 给定字符串s,s=a^n,a是s的子串,求n最大是多少 [思路] kmp中的next数组求最小循环节的应用 例如 ababab  next[6] = 4; 即 ababab ababab 1~4位  与2~6位是相同的 那么前两位 就等于3.4位 3.4位就等于5.6位 …… 所以 如果 能整除  也就循环到最后了 如果不能整除 就最后余下的几位不在循环内 例如 1212121 1212121 最后剩余1不能等于循环节 那么…
题目链接:http://poj.org/problem?id=2406 题意:确定字符串最多是多少个相同的字串重复连接而成的 思路:关键是找到字符串的最小循环节 code: #include <cstdio> #include <cstring> ; char s[MAXN]; int next[MAXN]; void GetNext() { int len = strlen(s); ; ; next[] = -; while (i < len) { == j || s[i]…
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 think of concatenation as multiplication, exponentiation by a non-negative inte…
http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strcmp/5495571?fr=aladdin ↑百度的概念 像 poj1961 但是更简单..主要是告诫我要学习一下str相关的函数,似乎说要学str函数好久了也没有经常用过 代码 #include<cstdio> #include<cstring> #include<iostre…
传送门 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 &…
题目链接:http://poj.org/problem?id=2406 题意:就是求一个字符串最多有几个相同的小字符串组成. 题解:直接求一下next然后找到长度,长度就是len-1-next[len-1]. #include <iostream> #include <cstring> using namespace std; const int M = 1e6 + 10; char s[M] , p[M]; int Next[M]; void getnext() { int le…
注意,在IDE运行时,可能会因为开的数组太大而报错,这时我们可以把数组开小一点来进行调试....提交的时候把数组的大小改成1000005即可.... #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1000005; int main() { char str[maxn]; while (scanf("%s",…