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

abcd
aaaa
ababab
.

Sample Output

1
4
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])。
 
 
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[];
int p[];
void makep(int l)
{
memset(p,,sizeof(p));
int j=;
for(int i=;i<l;i++)
{
while(a[i]!=a[j]&&j>)
j=p[j-];
if(a[i]==a[j])
j++;
p[i]=j;
}
}
void deal(int l)
{
int ans=;
if(l%(l-p[l-])==)
ans=l/(l-p[l-]);
printf("%d\n",ans);
}
int main()
{
while(scanf("%s",a)==)
{
if(a[]=='.')break;
int l=strlen(a);
makep(l);
deal(l);
}
return ;
}

最新文章

  1. Python之路 day2 集合的基本操作
  2. jsp页面验证码(完整实例)
  3. 查看linux [Fedora] 系统信息
  4. SharedPreferences保存用户登录信息
  5. Oracle中Blob和Clob类型的区别与操作
  6. 九度OJ 1514 数值的整数次方【算法】
  7. How to create XML validator(验证器;验证程序) from XML schema
  8. 温习H3C S5500的VLAN配置
  9. Mysql 添加用户和数据库授权
  10. .Net缓存
  11. C++雾中风景1:友元类与面向对象
  12. 浅谈对SpringMVC的认识
  13. 从.Net到Java学习第三篇——spring boot+mybatis+mysql
  14. 使用Keepalived配置主从热备实现Nginx高可用(HA)
  15. jquery Ajax 实现图片上传的功能。
  16. TensorFlow从入门到理解(三):你的第一个卷积神经网络(CNN)
  17. js对数组中的数字排序
  18. 14-03 java BigInteger类,BigDecimal类,Date类,DateFormat类,Calendar类
  19. ES6之Promise对象
  20. 【Struts2】剖析Struts2中的反射技术 ValueStack(值栈)

热门文章

  1. [APIO 2014] 序列分割
  2. C++模板之隐式实例化、显示实例化、隐式调用、显示调用和模板特化详解
  3. mybatis 优缺点和适用场合
  4. 注销ie中的ActiveX插件
  5. Linux Ctrl+Z的使用方法
  6. 3.15-3.21 hive项目实战
  7. Centos Mininal最小安装
  8. yzm10铺瓷砖 yzm10原创系列
  9. C# in查询
  10. HDU2819【二分匹配与矩阵的秩】