[poj2406]Power Strings KMP
来源:互联网 发布:修真的程序员txt下载 编辑:程序博客网 时间:2024/05/18 00:14
Power Strings
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 999999 Accepted: 99999
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
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>using namespace std;int nxt[1000005];char s[1000005];void getnxt(){int i = 0, j = -1;int len = strlen(s);nxt[0] = -1;while( i < len ){if( j == -1 || s[i] == s[j] ){i++; j++;nxt[i] = j;} else j = nxt[j];}}int main(){while(~scanf("%s", s) && s[0] != '.'){int ans = 1;getnxt();int len = strlen(s);if( len % (len-nxt[len]) == 0 ){ans = len / (len-nxt[len]);}printf("%d\n", ans);}return 0;}
阅读全文
0 0
- 【KMP】 poj2406 Power Strings
- poj2406 Power Strings-------KMP
- [POJ2406] Power Strings[KMP]
- poj2406 Power Strings kmp
- POJ2406 Power Strings 【KMP】
- poj2406 Power Strings (KMP)
- poj2406-Power Strings(kmp)
- poj2406 Power Strings(KMP)
- POJ2406 Power Strings【KMP】
- poj2406 power strings 【KMP】
- poj2406 Power Strings(KMP)
- 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
- 常见医疗扫描图像处理步骤
- IDEA忽略文件,防止git提交不想提交的文件的探索
- Mysql导出表结构及表数据 mysqldump用法
- python 常见bug解决方案记录
- Gstreamer源码安装(更新安装,基于ubuntu)
- [poj2406]Power Strings KMP
- Web移动端Fixed布局的解决方案
- RxSwift
- bzoj4926 皮皮妖的递推
- Spring中PropertyPlaceholderConfigurer类载入外部配置
- Redis和Memcache对比及选择
- shell 学习
- MYSQL:ERROR: Field '***' doesn't have a default value
- Spring任务调度<task:scheduled-tasks>【含cron参数详解】