POJ2406 Power Strings(KMP,循环节)
来源:互联网 发布:进销存软件破解版 编辑:程序博客网 时间:2024/05/21 10:06
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
integer is defined in the normal way: a^0 = “” (the empty string) and
a^(n+1) = a*(a^n).
Input
Each test case is a line of input representing s, a string of
printable characters. The length of s will be at least 1 and will not
exceed 1 million characters. A line containing a period follows the
last test case.
Output
For each s you should print the largest n such that s = a^n for some
string a.
Sample Input
abcdaaaaababab.
Sample Output
143
思路
最小循环节的裸题,判断
代码
#include<cstdio>#include<cstring>#include<string>#include<set>#include<iostream>#include<stack>#include<queue>#include<vector>#include<algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 1000000+20#define ll longlongusing namespace std;char s[N];int nxt[N];void get_next(int len){ int j=0,k=-1; nxt[0]=-1; while(j<len) if(k==-1||s[j]==s[k]) nxt[++j]=++k; else k=nxt[k];}int main(){ while(scanf("%s",s)&&s[0]!='.') { int len=strlen(s); get_next(len); int j=len-nxt[len]; if(len%j==0) printf("%d\n",len/j); else printf("1\n"); } return 0;}
阅读全文
0 0
- POJ2406-Power Strings(kmp循环节)
- poj2406 Power Strings(kmp求循环节)
- POJ2406 Power Strings(KMP,循环节)
- 【poj2406】 Power Strings (KMP求循环节)
- poj2406--Power Strings(KMP求最小循环节)
- POJ2406 Power Strings KMP-next数组的循环节
- [poj2406]Power Strings(kmp求最小循环节)
- poj2406——Power Strings(KMP循环节)
- poj2406(KMP 求循环节的个数)Power Strings --
- (POJ2406)Power Strings <KMP算法求最小循环节>
- 【KMP求最小循环节】POJ2406 Power Strings
- poj2406 Power Strings(kmp求最小循环节)
- 【KMP】 poj2406 Power Strings
- poj2406 Power Strings-------KMP
- [POJ2406] Power Strings[KMP]
- poj2406 Power Strings kmp
- POJ2406 Power Strings 【KMP】
- poj2406 Power Strings (KMP)
- 【数据结构 总论】---概述
- BP神经网络-感知器
- STM8单片机中断优先级问题
- 第三周总结(一)
- 2017年9月14日训练总结
- POJ2406 Power Strings(KMP,循环节)
- 【数据结构 一】---数组
- eXscan 网络扫描器
- android 4种引用类型
- 点击率预估
- 264. Ugly Number II
- 【数据结构 三】---栈
- centos 调教日记
- 【数据结构 四】---队列