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. C# Linq To DataTable 分组统计 DEMO

    DataTable dt = SQLLayer.Get工作量统计(beginDate, endDate);             var querySum = from t in dt.AsEnum ...

  2. 斗地主你什么时候才会托管?(.NET中的托管于非托管)

    文章部分引自<.NET4.0面向对象编程漫谈(基础篇)>第1章.NET面向对象编程基础(作者:金旭亮) 无意间看到一位四五岁左右小朋友在玩斗地主,总开始到结束,她一直都在使用“提示”(托管 ...

  3. IP工具类——IpAddress.java

    根据IP地址获取详细的地域信息,也可通过 http://whois.pconline.com.cn/ 获取地址信息. 源码如下:(点击下载  IpAddress.java) import java.i ...

  4. ASP.NET之HttpModule拦截404异常

    Httpmodule代码: public class Error404Module : IHttpModule { public void Init(HttpApplication context) ...

  5. Android 连接tomcat模拟登陆账号

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  6. 李洪强漫谈iOS开发[C语言-030]-逻辑运算符

  7. OA学习笔记-003-Hibernate3.6配置

    一.jar包:核心包, 必须包, jpa, c3p0, jdbc antlr-2.7.6.jarc3p0-0.9.1.jarcommons-collections-3.1.jardom4j-1.6.1 ...

  8. Android用户界面UI组件--AdapterView及其子类(三) ExpandableListView

    ExpandableListView: List中的每一项可以展开收缩. 一种伸缩式的ListView. android:cacheColorHint="#00000000" 这个 ...

  9. android原生系统裁剪

    Andriod 4.0.4系统包 Andriod 4.1.1系统包 说明   ApplicationsProvider.apk ApplicationsProvider.apk 应用程序存储. 程序管 ...

  10. linux字符图形界面

    /etc/inittab 1)  字符界面标识: id:3:initdefault: 2)  图形界面标识: id:5:initdefault:   [root@ora9i ~]# vi /etc/i ...