POJ 2406 Power Strings kmp
来源:互联网 发布:手机版商城源码 编辑:程序博客网 时间:2024/06/07 02:34
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 37817 Accepted: 15653
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
Hint
This problem has huge input, use scanf instead of cin to avoid time limit exceed.
Source
Waterloo local 2002.07.01
AC code:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#define maxn 1000005using namespace std;int next[maxn];int main(){ char s[maxn]; while(scanf("%s",s)!=EOF&&strcmp(s,".")){ int k=0,len=strlen(s),i,j; j=0,k=-1; next[0]=-1; while(j<len){ if(k==-1||s[j]==s[k]){j++;k++;if(s[j]!=s[k])next[j]=k; else next[j]=next[k]; } else k=next[k]; } if(len%(len-next[len])==0) cout<<(len/(len-next[len]))<<'\12'; else printf("1\n"); } return 0;}
0 0
- poj 2406 Power Strings---kmp
- POJ 2406 Power Strings KMP
- poj-2406-Power Strings-kmp
- POJ-2406 Power Strings KMP
- Power Strings - POJ 2406 KMP
- poj 2406 Power Strings kmp
- POJ 2406-Power Strings (KMP)
- 【KMP】 POJ 2406 Power Strings
- poj 2406 Power Strings KMP
- POJ 2406 Power Strings KMP
- poj 2406 Power Strings KMP
- poj 2406 Power Strings (KMP)
- [2406]Power Strings (POJ) KMP
- Power Strings (poj 2406 KMP)
- poj 2406 Power Strings【KMP】
- POJ 2406 Power Strings(KMP)
- poj-2406 Power Strings 【kmp】
- POJ 2406--Power Strings【KMP】
- 解决 iOS8 定位授权的问题
- CWnd与HWND的区别 (2
- Poj 4227 反正切函数的应用
- 9.10扩展性与存储限制(二)——给定一个输入文件,包含40亿个非负整数。产生一个不在该文件中的整数。内存限制:1GB
- Android 四种点击监听方式
- POJ 2406 Power Strings kmp
- Codeforces Round #199 (Div. 2) C. Cupboard and Balloons
- hdu 5381 The sum of gcd(线段树+gcd)
- java 里面保留字volatile及其与synchronized的区别
- 黑马程序员----反射(Reflect)
- iOS 手势识别 ——长按和轻扫(swipe)
- 通讯录篇
- 使用background-position 定位背景图片 要注意优先级
- poj 3264 -- RMQ模板题