Power Strings(poj 2406)】的更多相关文章

题意:求字符串中循环节出现的次数 KMP!!! #include<cstdio> #include<iostream> #include<cstring> #define M 1000010 using namespace std; int fail[M],a[M],m; char ch[M]; void kmp_init() { fail[]=; ;i<=m;i++) { ]; ]!=a[i])p=fail[p]; ]==a[i]) fail[i]=p+; ;…
题目大意,给出一个字符串s,求最大的k,使得s能表示成a^k的形式,如 abab 可以表示成(ab)^2: 方法:首先 先求kmp算法求出next数组:如果 len mod (len-next[len])==0 ,答案就是 len /(len-next[len]),否则答案是1:证明如下: 如果s能表示成 a^k的形式且k>1,k尽可能大,即s可以表示成aaaaaa(k个a):那么next[len]就等于k-1个a的长度:aaaaaaa  aaaaaaa那么 (len-next[len])a的长…
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include <cstdio> #include <cstring> using namespace std; const int maxn=2e6+5; char s1[maxn], s2[maxn]; int n1, n2, nxt[maxn], ans; int main(){ while (~…
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 = "…
题目链接: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…
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 = "…
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 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 = "abcd…
Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 11954   Accepted: 5105 Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. Input The input contains exactly one test cas…
Power Strings 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…
题目大意:给定A,k,m(取模),求解S = A + A2 + A3 + … + Ak. 思路:此题为求解幂的和,一开始直接一个个乘,TLE.时间消耗在累加上.此处巧妙构造新矩阵 p=    A 0 1 1 ,1 代表单位矩阵.那么p*p=A 0 A+1,1 p*p*p=A*A 0 A*A+A+1 1 那么最后求得的结果就是左下角的矩阵减去一个单位矩阵.最后需要注意的是若在简单为矩阵的时候结果为负数,那么为m-1; #include <iostream> #include <cstrin…