poj 2406 Power Strings(kmp循环节)】的更多相关文章

<题目链接> 题目大意: 给出一个字符串,求其字串在该字符串中循环的最大周期. 解题分析: length=len-Next[len],len为该字符串的最小循环节,如果len%length==0,那么周期就为len/lenght,如果不能整除,则说明该字符串的字串不具有周期性,输出1. KMP最小循环节的证明 >>> #include <cstdio> #include <cstring> + ; char str[maxn]; int Next[ma…
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…
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…
题目链接: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…
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: 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 =…
传送门 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的next数组计算出来的,一直都认为是能够利用next数组的.可是自己想了非常久没能这么简洁地总结出来,也仅仅能查查他人代码才恍然大悟,原来能够这么简单地区求一个周期字符串的最小周期的. 有某些大牛建议说不应该參考代码或者解题报告,可是这些大牛却没有给出更加有效的学习方法,比方不懂KMP.难倒不应该去看?要自己想出KMP来吗?我看不太可能有哪位大牛能够直接自己"又一次创造出KMP"来吧. 好吧.不说"创造…
题意:给一个字符串,求该串最多由多少个相同的子串相接而成. 思路:只要做过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[…
对于数组s[0~n-1],计算next[0~n](多计算一位). 考虑next[n],如果t=n-next[n],如果n%t==0,则t就是问题的解,否则解为1. 这样考虑: 比方字符串"abababab", a  b a b a b a b * next     -1 0 1 2 3 4 5 6  7 考虑这种模式匹配,将"abababab#"当做主串."abababab*"当做模式串.于是进行匹配到n(n=8)时,出现了不匹配: 主串    …
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************************ * Author :Running_Time * Created Time :2015-8-10 10:51:54 * File Name :POJ_2406.cpp ************************************************/ #incl…
连续重复子串问题 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 Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少次得到. analyse: KMP之next数组的运用.裸的求最小循环节. Time complexity: O(N) Source code:  ;;      ;);      ) ;}/* */…
                                                                                                  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…
题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的等式之后就知道是求a的n次方,也就是说求所给字符串的最大循环次数,想一想. 如果可以求出所给字符串的最小循环节, 那么是不是就可以求出它的最大循环次数了.   这是肯定的. 因为循环节最小. 循环次数也就最大 #include<iostream> #include<cstring> #…
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不能等于循环节 那么…
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 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 = "…
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 = "…
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 = "…
Time Limit: 3000MSMemory 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 think of concatenation as multiplication…
题意:求最小循环节循环的次数. 题解:这个题其实可以直接用kmp去求最小循环节,然后在用总长度除以循环节.但是因为在练后缀数组,所以写的后缀数组版本.用倍增法会超时!!所以改用DC3法.对后缀数组还不是很理解,找了很多博客也没看懂到底有些数组到底记录的是啥,但他的实现过程很好理解,等我弄懂了再来给博客加注释吧. 先求出sa数组,height数组,rank数组(因为和c++库中某个东西重了所以写成rnk数组),数组一定要开3倍.接下来从小到大枚举循环节长度 i,如果长度i的子串刚好是重复了len/…
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 = "…
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 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是求字符串的最小循环节. 以下内容转载于:http://bbezxcy.iteye.com/blog/1377787 --------------------------------------------------------------------------------------------…
题目: 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+…
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 题目大意:如果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…