[poj2406]Power Strings_hash】的更多相关文章

Power Strings poj-2406 题目大意:询问一个字符串最多几个相同且连续的字符串构成(Eg:abababab由4个构成,abcd由1个构成). 注释:字符串长度为n,$1\le n\le 10^6$. 想法:hash裸题,通过Hash求出单个字符串的hash前缀,然后用n的约数以及hash值判定即可. 最后,附上丑陋的代码... ... #include <cstdio> #include <iostream> #include <cstring> #i…
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 (~…
题目链接:https://vjudge.net/problem/POJ-2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 52631   Accepted: 21921 Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc"…
给你一个串s,如果能找到一个子串a,连接n次变成它,就把这个串称为power string,即a^n=s,求最大的n. 用KMP来想,如果存在的话,那么我每次f[i]的时候退的步数应该是一样多的  譬如ababab  我每次退的一定是2步,检验一下这个串的失配指针是不是这个性质,如果是的话,那么n=strlen(s)/退的步数,否则就是直接1好了. #include<iostream> #include<cstring> #include<cstdio> #includ…
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…
如果next[n]<n/2,一定无解. 否则,必须要满足n mod (n-next[n]) = 0 才行,此时,由于next数组的性质,0~n-next[n]-1的部分一定是最小循环节. [ab ababababab ab] #include<cstdio> #include<cstring> using namespace std; char s[1000010]; int next[1000010]; void GetFail(char P[],int next[])//…
Power Strings   Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 47748   Accepted: 19902 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 = &quo…
Description 对于两个字符串a,b,定义a×b为将b接到a的末尾组成新的字符串.对于一个字符串a的幂运算的定义与我们在数学中的定义一样:a0=''(空字符),an+1=an×a. Input 输入数据每一行为一个字符串,长度为L(1<=L<=1000000).输入数据以'.'结尾. Output 对于每个字符串s,输出最大的n使得字符串s满足条件:s=an(a为一个字符串). Sample Input abcd aaaa ababab . Sample Output 1 4 3 So…
这题可以用后缀数组,KMP方法做 后缀数组做法开始想不出来,看的题解,方法是枚举串长len的约数k,看lcp(suffix(0), suffix(k))的长度是否为n- k ,若为真则len / k即为结果. 若lcp(suffix(0), suffix(k))的长度为n- k,则将串每k位分成一段,则第1段与第2段可匹配,又可推得第2段与第3段可匹配……一直递归下去,可知每k位都是相同的,画图可看出匹配过程类似于蛇形. 用倍增算法超时,用dc3算法2.5秒勉强过. #include<cstdi…
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 integer is defin…