poj 2406 Power Strings(kmp)
来源:互联网 发布:鹿晗 知乎 编辑:程序博客网 时间:2024/05/17 03:05
http://poj.org/problem?id=2406
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-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 <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>#include <vector>#include <map>using namespace std;#define N 1010000#define INF 0x3f3f3f3f#define PI acos (-1.0)#define EPS 1e-8#define met(a, b) memset (a, b, sizeof (a))char s[N];int Next[N];void get_next (char s[], int n, int Next[]);int main (){ while (scanf ("%s", s), strcmp (s, ".")) { int len = strlen (s); get_next (s, len, Next); int l = len - Next[len]; if (len % l) puts ("1"); else printf ("%d\n", len/l); } return 0;}void get_next (char s[], int n, int Next[]){ int i = 0, j = -1; Next[i] = -1; while (i < n) { if (j == -1 || s[i] == s[j]) Next[++i] = ++j; else j = Next[j]; } return;}
1 0
- poj 2406:Power Strings(KMP)
- poj 2406 Power Strings(kmp算法)
- POJ 2406 Power Strings(kmp)
- POJ 题目2406 Power Strings(KMP)
- POJ 2406 Power Strings(kmp)
- poj 2406 Power Strings (KMp)
- POJ 2406 Power Strings (KMP)
- POJ 2406 Power Strings(KMP)
- poj-2406-Power Strings(KMP)
- poj 2406 Power Strings(kmp)
- poj 2406Power Strings(KMP入门)
- poj 2406 Power Strings(KMP || 暴力)
- poj 2406 Power Strings(KMP)
- POJ 2406 Power Strings(KMP)
- 【POJ】2406 - Power Strings(KMP)
- POJ 2406 Power Strings(KMP)
- poj 2406 Power Strings-字符串(kmp)
- poj 2406 Power Strings(KMP)
- 随手写的一些好用的功能(不定时更新)
- leetcode278:First Bad Version
- 敏捷自动化测试
- 字符串常量池
- 5张图让你彻底理清数据库 ,数据源和连接池的关系
- poj 2406 Power Strings(kmp)
- 测试android事件分发
- 寻找指定元素的指针
- Android中封装Http请求
- 幸福来敲门观后感
- php和mysql学习之旅
- Julia: 关于Github上的其它库
- Linux安装MySQL的两种方法
- 求两个树结点的最低公共祖先(Again)