Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 56162   Accepted: 23370

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

abcd
aaaa
ababab
.

Sample Output

1
4
3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

Source

 
 
kmp的经典应用
设$len$表示字符串的长度,$next[i]$表示$i$号字符串的最长公共前后缀的长度
如果$len \ mod  \  next[len] == 0$,那么循环节的长度为$n / next[len]$
 
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1e6 + ;
char s[MAXN];
int fail[MAXN];
int main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
//freopen("a.out", "w", stdout);
#endif
while(scanf("%s", s + ) && s[] != '.') {
int N = strlen(s + ), now = ;
for(int i = ; i <= N; i++) {
while(now && s[i] != s[now + ]) now = fail[now];
if(s[i] == s[now + ]) now++;
fail[i] = now;
}
if(N % (N - fail[N]) == ) printf("%d\n", N / (N - fail[N]));
else printf("1\n");
}
return ;
}
 
 

POJ2406 Power Strings(KMP)的更多相关文章

  1. POJ2406 Power Strings —— KMP or 后缀数组 最小循环节

    题目链接:https://vjudge.net/problem/POJ-2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  2. poj2406 Power Strings (kmp 求最小循环字串)

    Power Strings   Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 47748   Accepted: 19902 ...

  3. POJ2406 Power Strings KMP算法

    给你一个串s,如果能找到一个子串a,连接n次变成它,就把这个串称为power string,即a^n=s,求最大的n. 用KMP来想,如果存在的话,那么我每次f[i]的时候退的步数应该是一样多的  譬 ...

  4. POJ2406 Power Strings(KMP,后缀数组)

    这题可以用后缀数组,KMP方法做 后缀数组做法开始想不出来,看的题解,方法是枚举串长len的约数k,看lcp(suffix(0), suffix(k))的长度是否为n- k ,若为真则len / k即 ...

  5. poj2406 Power Strings(kmp)

    poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include & ...

  6. poj2406 Power Strings(kmp失配函数)

    Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 Descr ...

  7. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  8. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

  9. Power Strings(kmp妙解)

    Power Strings Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

随机推荐

  1. tushare获取的数据与mysql数据库交互简单范例

    #!/usr/bin/python2.7# -*- coding: UTF-8 -*- import tushare as tsimport pandas as pdfrom sqlalchemy i ...

  2. Backbone事件机制核心源码(仅包含Events、Model模块)

    一.应用场景 为了改善酷版139邮箱的代码结构,引入backbone的事件机制,按照MVC的分层思想搭建酷版云邮局的代码框架.力求在保持酷版轻量级的基础上提高代码的可维护性.   二.遗留问题 1.b ...

  3. link 和 import 导入外部样式的区别

    差别一:link 属于 XHTML 标签,而 @import 完全是 CSS 提供的 一种方式.link标签除了可以加载 CSS 外,还可以做很多事情,比如定义 RSS ,定义 rel 链接属性等.  ...

  4. 【HTML&CSS】文本的基本处理

    其实在写这篇博客的时候已经学了很久,也写了不少代码,特别是很枯燥的看完整个html部分,因为不带有CSS写出来的东西干巴巴的一点也不好看. 直到展开CSS学习才开来补上博客,嗯,这是个好习惯. 这是运 ...

  5. ArcGIS for Server安全与LDAP配置

    ArcGIS for Server安全与LDAP配置 1.安全性概述 ArcGIS Server使用基于角色的访问控制来管理对受保护资源的访问.访问GIS资源的权限只能分配给角色.单独的用户只能通过从 ...

  6. SharePoint 2013 - Add-ins

    1. App Web & Host Web The special website to which the app is deployed is called an App Web. The ...

  7. ArcGIS Geodabase OBJECTID重新初始编号的间接方法

    ArcGIS Geodabase OBJECTID为Long型,随着Feature的增加和删除自动编号,均为增加.即删除Feature后,再增加该号码自动只增加不重新编号. 间接方法可以实现重新从1编 ...

  8. 超简便的ListView中Adapter的写法

    对于 ListView 的使用,他有两个重点的部分,一个是下拉刷新和加载更多,这个今天我们不讲,另外一个是 BaseAdapter 的使用,这个是今天的主角,BaseAdapter 中又有 ViewH ...

  9. QTablewidget 简单例子

    [1]QTableWidget简介 QTableWidget是QT对话框设计中常用的显示数据表格的控件. 学习QTableWidget就要首先看看QTableView控件(控件也是有”家世“的!就像研 ...

  10. window medio player 完美代码

    var arr = [               '<object width="240" height="240" align="basel ...