E - Power Strings

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 讲了这么多,其实就是一个求一个字符串里最小周期的问题。限时有3S,我们可以用枚举。
这里需要注意的是一个:求周期串的基本算法:
for(i=1;i<=len;i++)
{
ok=1;
if(len%i==0)
{
for(j=i;j<len;j++)
{
if(s[j]!=s[j%i]){ok=0;break;}
}
}
if(ok==1)
{
printf("%d\n",len/i);
break;//记得要break
}
}
 #include<cstdio>
#include<string.h>
using namespace std;
char s[];
int main()
{
while(scanf("%s",s)==&&strcmp(s,".")!=)
{
int len=strlen(s); for(int i=;i<=len;i++)
if(len%i==)
{
int ok=;
for(int j=i;j<len;j++)
{
if(s[j]!=s[j%i])
{
ok=;
break;
}
}
if(ok)
{
printf("%d\n",len/i);
break;
} }
}
return ;
}

E - Power Strings,求最小周期串的更多相关文章

  1. 【KMP求最小周期】POJ2406-Power Strings

    [题意] 给出一个字符串,求出最小周期. [思路] 对KMP的next数组的理解与运用orz ①证明:如果最小周期不等于它本身,则前缀和后缀必定有交叉. 如果没有交叉,以当前的next[n]为最小周期 ...

  2. UVa455 最小周期串问题

    A character string is said to have period k if it can be formed by concatenating one or more repetit ...

  3. poj 2406 Power Strings【最小循环节】

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

  4. (字符串的模式匹配4.7.18)POJ 2406 Power Strings(求一个字符串的最小重复串)

    注意,在IDE运行时,可能会因为开的数组太大而报错,这时我们可以把数组开小一点来进行调试....提交的时候把数组的大小改成1000005即可.... #include <iostream> ...

  5. Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏

    Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...

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

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

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

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

  8. POJ--2406Power Strings+KMP求字符串最小周期

    题目链接:点击进入 事实上就是KMP算法next数组的简单应用.假设我们设这个字符串的最小周期为x 长度为len,那么由next数组的意义,我们知道len-next[len]的值就会等于x.这就是这个 ...

  9. poj2406--Power Strings(KMP求最小循环节)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33178   Accepted: 13792 D ...

随机推荐

  1. urlencode在url中的作用

    urlencode编码能解决特殊字符的传输问题. 使用urlencode主要用于正常识别输入的汉字.空格以及其他特殊字符. 列如: 一产品名称为A&T Plastic,在产品列表中就产生了这样 ...

  2. js 替换 当前URL 特定参数

    js 替换 当前URL 特定参数 2012-12-24 20:45:53|  分类: JS&JQuery |举报 |字号 订阅   //替换指定传入参数的值,paramName为参数,repl ...

  3. flash builder的编译缓存

    C:\Users\Administrator\AppData\Roaming 因为我的一个项目是手机.浏览器都支持的项目,所以我经常删除项目然后修改成别的类型: 可能是这个原因,导致我的程序或者加载的 ...

  4. POJ 1753 Flip Game 状态压缩,暴力 难度:1

    Flip Game Time Limit: 1000MS  Memory Limit: 65536K  Total Submissions: 4863  Accepted: 1983 Descript ...

  5. HDU 1828 扫描线(矩形周长并)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  6. 文件浏览器及数码相框 -2.3.1freetype_pc

    例子 #include <stdio.h> #include <string.h> #include <math.h> #include <ft2build. ...

  7. wechat

  8. javascript 错误处理

    try{ var date=new Date(); date.test();//调用date的未定义的test方法; document.wrire("try块执行结束<br>&q ...

  9. hadoop源码阅读

    1.Hadoop的包的功能分析 2.由于Hadoop的MapReduce和HDFS都有通信的需求,需要对通信的对象进行序列化.Hadoop并没有采用java的序列化,而是引入它自己的系统.org.ap ...

  10. how to reset mac root password

    Reset 10.5 Leopard & 10.6 Snow Leopard password Power on or restart your Mac. At the chime (or g ...