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 ;
}

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. Tutte矩阵求一般图最大匹配

    [集训队2017论文集] 一张无向图的Tutte矩阵为 其中xi,j为一个random的值. Tutte矩阵的秩(一定为偶数)/2 就是这张图的最大匹配. 原理大概就是: 一个图有完美匹配,则det( ...

  2. 将DotNetBar添加到工具箱中

    一.首先得安装DotNetBar; 二.在工具箱的空白处右击=====>添加选项卡(图一)======>命名为DotNetBar(图二) 图一 图二 三.右击DotNetBar====== ...

  3. web单机优化

    又得开始写博客了,目测又要一周一篇了,当然了这不算python跟前端的,个人喜欢notepad++可惜不能放图片,word什么的太讨厌了 为什么要单机优化呢,很简单,因为不论以后是各类集群也好,物理机 ...

  4. bzoj5102

    $贪心$ $按左端点排序.$ $当我们钦定了最右的左端点,那么自然希望右端点尽量靠右$ $考虑之前的区间,那么我们相当于选之前的区间中第k大的右端点$ $堆维护一下就可以了,每次把新的元素放进堆,如果 ...

  5. bzoj3168

    二分图+矩阵求逆 既然我们考虑b能替换哪些a,那么我们自然要得出b被哪些a表示,这里我们设一个矩阵C,那么C*A = B 为什么呢?直接A*C = B是不可行的,因为都是行向量,不能直接乘,那么我们转 ...

  6. 单例模式-Lazy initialization holder class模式

    这个模式综合使用了Java的类级内部类和多线程缺省同步锁的知识,很巧妙地同时实现了延迟加载和线程安全. 1.相应的基础知识 什么是类级内部类? 简单点说,类级内部类指的是,有static修饰的成员式内 ...

  7. Flutter实战视频-移动电商-46.详细页_自定义TabBar Widget

    46.详细页_自定义TabBar Widget 主要实现详情和评论的tab provide定义变量 自己做一个tab然后用provide去控制 定义两个变量来判断是左侧选中了还是右侧选中了.并定义一个 ...

  8. LeetCode: 620 Not Boring Movies(easy)

    题目: X city opened a new cinema, many people would like to go to this cinema. The cinema also gives o ...

  9. Grid++Report应用(引入项目中)

    1.将Grid++Report安装文件中(\WebSamples\asp.net(csharp)\App_Code)的ReportData.cs,MssqlReportData.cs两个文件复制到自己 ...

  10. 1118 Birds in Forest (25 分)

    Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in ...