Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 48139   Accepted: 20040

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

  1. abcd
  2. aaaa
  3. ababab
  4. .

Sample Output

  1. 1
  2. 4
  3. 3

Hint

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

Source

 
百度扯淡:
内存限制:时间限制:3000ms 65536k

意见:总48139 20040接受:

描述

我们给出两个字符串A和B是定义了他们的concatenation *。例如,如果A和B =“abc”,然后在“def”=“*(ABCDEF)”。如果我们想到的exponentiation concatenation繁殖,用非负整数的定义为:在正常的方式(0 =“”(空字符串)和(N + 1)=(n×公尺)。

输入

每个测试用例的输入线,代表的是一个可打印的字符,字符串)。S的长度将至少1百万的人物将不超过1。含周期线为最后的测试案例。

输出
你应该为每个打印最大的N,S = N次这样的一些字符串。

样本输入
ABCD
AAAA
ABABAB
.
示例输出
1
4
3
提示
这个问题有巨大的投入,而不是使用scanf的CIN,避免超过时间限制。
源代码
当地的2002.07.01滑铁卢
 
 
假设 S 的周期大于 1。假设 S 存在周期 X,而且每
个周期的长度为 L。那么,我们有 S[1..n-L] = S[L+1…n],
对于 i=n 来说,n-L 是一个合法的 j。
* 由于 P 数组所求的是所有 j 的最大值,所以只要判断 P[n] 即
可。如果 P[n] < n/2,则说明 S 不存在周期;否则最小的周期
长度为 n-p[n],对应的周期为 n / (n – p[n])。
 
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5. char a[];
  6. int p[];
  7. void makep(int l)
  8. {
  9. memset(p,,sizeof(p));
  10. int j=;
  11. for(int i=;i<l;i++)
  12. {
  13. while(a[i]!=a[j]&&j>)
  14. j=p[j-];
  15. if(a[i]==a[j])
  16. j++;
  17. p[i]=j;
  18. }
  19. }
  20. void deal(int l)
  21. {
  22. int ans=;
  23. if(l%(l-p[l-])==)
  24. ans=l/(l-p[l-]);
  25. printf("%d\n",ans);
  26. }
  27. int main()
  28. {
  29. while(scanf("%s",a)==)
  30. {
  31. if(a[]=='.')break;
  32. int l=strlen(a);
  33. makep(l);
  34. deal(l);
  35. }
  36. return ;
  37. }

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 (kmp 中 next 数组的应用||后缀数组)

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

  4. POJ 2406 Power Strings (KMP)

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

  5. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

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

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

  7. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  8. poj 2406 Power Strings kmp算法

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

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

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

随机推荐

  1. 「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp

    题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N ...

  2. 非旋treap套线段树

    BZOJ3065. 去年用pascal 块链过了.. 今年来试了试非旋treap大法   注定被块链完爆 代码留这. 第一份 :辣鸡的  垃圾回收做法  跑得极慢 #include <bits/ ...

  3. 洛谷P1522牛的旅行——floyd

    题目:https://www.luogu.org/problemnew/show/P1522 懒于仔细分情况而直接像题解那样写floyd然后不明白最后一步max的含义了... 分开考虑怎么保证在一个内 ...

  4. cobbler api

    try: import xmlrpclib except ImportError as e: import xmlrpc.client SERVER_IP = '192.168.144.11' try ...

  5. 使用json-lib的JSONObject.toBean( )时碰到的日期属性转换的问题

    今天碰到这样一个问题:当前台以JSON格式向后台传递数据的时候,对于数据中的日期属性,无法正常转换为相应的Date属性.JSON数据是这样的:{"birthday":"1 ...

  6. iOS 中这些是否熟练掌握——(2)

    接上一篇博文,本篇博文是作者原创,用于记录从网上查阅的一些资料,并对自己的知识体系进行一下总结,成文以供学习使用. 1.Cocoa Touch 包含了什么?不包含什么?与 Cocoa 有什么区别? 相 ...

  7. javamail - 发件、收件(SSL连接)

    需要的包:mail.jar  jsse.jar(说明:jsse.jar是jre自带的,如果jdk1.5及以下需要Java Activation Framework框架的activation.jar) ...

  8. conditon_variable(条件变量)用于线程间同步

    conditon_variable(条件变量)用于线程间同步 condition_variable有5个函数,函数名及对应的功能如下: wait阻塞自己,等待唤醒 wait_for阻塞自己,等待唤醒, ...

  9. secureCRT访问centOS中文系统乱码问题

    第一种修改linux和crt的编码方式为utf-8 第二种修改linux和crt的编码为GB2312, 重要!!!crt字体要改成新宋体,同时字符集要改为GB2312 加上最后一项后,成功解决了中文乱 ...

  10. xml的的特殊字符转义&

    &amp   ampersand   连接符   & &quot   quotation     双引号    “ &apos  apostrophe   单引号   ...