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. 开发excel 自定义func

    http://www.cnblogs.com/brooks-dotnet/archive/2011/01/16/1936871.html http://club.excelhome.net/threa ...

  2. Masonry使用案列详解

    案例一: 要求:无论在什么尺寸的设备上(包括横竖屏切换),红色view都居中显示.

  3. Div层的展开与收缩的代码

    <html> <head> <title>div展开收缩代码</title> <style> * { margin:0; padding:0 ...

  4. hdu 4612 Warm up

    http://acm.hdu.edu.cn/showproblem.php?pid=4612 将原图进行缩点 变成一个树 树上每条边都是一个桥 然后加一条边要加在树的直径两端才最优 代码: #incl ...

  5. (BFS)hdoj2377-Bus Pass

    题目地址 因为最后要看的是到所有路线上的区域最大距离最小的中心点,所以可以采取遍历路线上所有的区域,对每个区域进行BFS的办法.为了更方便的在每一次BFS都遍历所有的区域,可以加一个reach数组,记 ...

  6. 从报错“无效操作,连接被关闭”探究Transaction的Timeout超时机制

    1.报错如下:Invalid Operation the connection is closed,无效操作,连接被关闭.这个错误是并不是每次都报,只有在复杂操作.大事务的情况下才偶然报出来. sta ...

  7. POJ 3691 AC自动机上的dp

    题目大意: 给定一些不合理的DNA序列,再给一段较长的dna序列,问最少修改几次可以使序列中不存在任何不合理序列,不能找到修改方法输出-1 这里你修改某一个点的DNA可能会影响后面,我们不能单纯的找匹 ...

  8. HighAvailability和LoadBalancer

    HighAvailability                         LoadBalancer 红帽RHCS                                lvs(三种工作 ...

  9. Program A-归并排序

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...

  10. 弹框工作区(dialog)

    弹出窗口分为普通弹出窗口和模态弹出窗口,普通弹出窗口可以铜鼓taskBar组件进行最小化等操作.弹出的窗口的DOM结构会放入主页面的body中,结构如下: <div class="bj ...