Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 36926   Accepted: 15254

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
mp算法:
#include<stdio.h>
#include<string.h>
#define MAX 1100000
char str[MAX];
int f[MAX];
void getfail()//失配函数 此函数定义出的数组f表示当原字符串与目标字符串失配
{ //后可以根据f[]跳转到原字符串相应位置从而提高运算的效率
int i,j;
int len=strlen(str);
j=0;
f[0]=f[1]=0;
for(i=1;i<len;i++)
{
j=f[i];
while(j && str[i] != str[j])
j = f[j];
f[i+1] = str[i] == str[j]?j+1:0;
}
}
int main()
{
int n,m,j,i,s,t;
while(scanf("%s",str)&&str[0]!='.')
{
getfail();
int len = strlen(str);
if(len%(len-f[len]))//此处len-f[len]的意思是原字符串中最大循环节的长度
printf("1\n"); //len%(len-f[len]有余数则证明除去最大循环节所有的节数仍然有
//不可循环的字符
else
printf("%d\n",len/(len-f[len]));//如果原字符的最大循环节可以将整个字符串表示完毕
} //则输出循环次数
return 0;
}

poj 2406 Power Strings【最小循环节】的更多相关文章

  1. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  2. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

  3. POJ 2406 Power Strings(字符串的最小循环节)

    题目链接:http://poj.org/problem?id=2406 题意:确定字符串最多是多少个相同的字串重复连接而成的 思路:关键是找到字符串的最小循环节 code: #include < ...

  4. KMP + 求最小循环节 --- POJ 2406 Power Strings

    Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...

  5. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  6. poj 2406 Power Strings(kmp应用)

    题目链接:http://poj.org/problem?id=2406 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是 ...

  7. POJ 2406 Power Strings (KMP)

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

  8. POJ 2406 Power Strings next数组循环节应用、

    题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的 ...

  9. POJ - 2406 Power Strings (后缀数组DC3版)

    题意:求最小循环节循环的次数. 题解:这个题其实可以直接用kmp去求最小循环节,然后在用总长度除以循环节.但是因为在练后缀数组,所以写的后缀数组版本.用倍增法会超时!!所以改用DC3法.对后缀数组还不 ...

随机推荐

  1. jQuery设置checkbox全选(区别jQuery版本)

    jQuery设置checkbox全选在网上有各种文章介绍,但是为什么在我们用他们的代码的时候就没有效果呢? 如果你的代码一点错误都没有,先不要急着怀疑人家代码的正确性,也许只是人家跟你用的jQuery ...

  2. 如何查看MySQL中每张表占用的空间大小

    如题,找到MySQL中的information_schema表,这张表记录了所有数据库中表的信息,主要字段含义如下: TABLE_SCHEMA : 数据库名 TABLE_NAME:表名 ENGINE: ...

  3. Class TBoundlabel not found and so on..

    Class TBoundlabel not found when you put a labeledit into a panel of CategoryPanel then you'll found ...

  4. hadoop1中hdfs原理详解

    HDFS是Hadoop Distribute File System的简称,也是Hadoop的一个分布四文件系统 一.HDFS的主要设计理念 1.存储超大文件 这里的 “超大文件” 是指几百MB .G ...

  5. linux安装ruby ruby-devel rubygems bundler

    linux安装ruby ruby-devel rubygems yum install ruby ruby-devel rubygems 安装bundler gem install bundleror ...

  6. 查看Oracle表空间使用情况与增大表空间

    1,查看表空间使用情况 SELECT D.TABLESPACE_NAME, SPACE || 'M' "SUM_SPACE(M)", BLOCKS "SUM_BLOCKS ...

  7. python面向对象编程实例解析

    1. 类和函数 面向对象编程的例子: #!/usr/bin/env python # -*- coding: utf-8 -*- class Person(object): #在属性和变量的前面增加“ ...

  8. HTML5 Geolocation

    http://diveintohtml5.info/geolocation.html http://msdn.microsoft.com/en-us/library/windows/apps/hh44 ...

  9. 关于后缀数组的倍增算法和height数组

    自己看着大牛的论文学了一下后缀数组,看了好久好久,想了好久好久才懂了一点点皮毛TAT 然后就去刷传说中的后缀数组神题,poj3693是进化版的,需要那个相同情况下字典序最小,搞这个搞了超久的说. 先简 ...

  10. 李洪强iOS开发Swift篇—05_元组类型

    李洪强iOS开发Swift篇—05_元组类型 一.元组类型介绍 1.什么是元组类型 元组类型由 N个 任意类型的数据组成(N >= 0),组成元组类型的数据可以称为“元素” 示例: let po ...