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. Java笔记(四)

    13. 集合框架: 集合中存储的都是对象的引用(地址) 迭代器:集合的取出元素的方式 import java.util.ArrayList; import java.util.Iterator; pu ...

  2. [Java] 练习题001:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

    [程序1]题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?1.程序分析: 兔子的规律为数列1,1,2 ...

  3. java定时器Timer的使用

    Time类主要负责完成定时计划任务的功能,就是在指定的时间的开始执行某个任务. Timer类的作用是设置计划任务,而封装任务内容的类是TimerTask类.此类是一个抽象类,继承需要实现一个run方法 ...

  4. HDOJ-1280

    前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. 1.1-1.4 hadoop调度框架和oozie概述

    一.hadoop调度框架 Linux Crontab Azkaban https://azkaban.github.io/ Oozie http://oozie.apache.org/ Zeus(阿里 ...

  6. Flutter实战视频-移动电商-47.详细页_Flutter_html插件的使用

    47.详细页_Flutter_html插件的使用 详情里面是hemlt和图片组成的,但是flutter是不支持html的所以需要其他插件 flutter webview plugin:这个不太好用 f ...

  7. 【废弃】JavaScript 删除部分

    创建: 2019/02/26 添加: 2019/02/06 添加Object部分 添加: 2019/03/09 添加Function部分 毕竟自己曾经写的,彻底删得不留痕迹还是舍不得的. 但是的确已经 ...

  8. 读取MySQL数据表字段信息

    TP5句式 $fieldinfo = Db::query('SHOW FULL COLUMNS FROM '.$table);//查出数据表所有字段信息Field 字段Comment 字段注释

  9. HDU2846【字典树】

    题意: 百度. 思路: 一个串的插入只能搞出这个串的前缀,然而对于要query的串是子串,所以插入的时候暴力插入所有字母开头的串.... 然后还要注意到自己的串本身会叠加字典树中的前缀,要标记掉. # ...

  10. Codeforces Round #374 (Div. 2)【A,B,C】

    = =C题这种DP打的少吧,记得以前最短路分层图打过这样子的,然后比赛前半个小时才恍然大雾...然后瞎几把还打错了,还好A,B手速快..上分了: A题: 计算B的连续个数的组数,每组的连续个数: 水题 ...