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. 小工具之Synergy

    用于两个主机共享键盘和鼠标的工具: 软件名字:synergy软件主页: http://synergy-foss.org支持平台:linux,mac,windows 通吃 作用:通过网络在多台主机之间共 ...

  2. codevs 4768跳石头

    传送门 4768 跳石头  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold  题目描述 Description 一年一度的“跳石头”比赛又要开始了! 这项比赛将在 ...

  3. 【Boost】boost库asio详解2——io_service::run函数无任务时退出的问题

    io_service::work类可以使io_service::run函数在没有任务的时候仍然不返回,直至work对象被销毁. void test_asio_nowork() { boost::asi ...

  4. 使用Java进行udp-demo编程时碰到的consumer和producter无法连接并报出“java.net.SocketException: Can't assign requested address”问题

    在用Java编写了一个udp生产者和消费者的demo时,在生产者启动的时候会抛出异常 java.net.SocketException: Can't assign requested address ...

  5. HDOJ-1280

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

  6. ESXI中 Linux虚拟机不重启扩展磁盘

    1.首先对虚拟机进行编辑设置 硬盘大小进行修改到80G: 2.在Linux系统中查看磁盘大小 此时并没有什么变化: 3. 上面没有变化的原因,是因为需要重新扫描存储设备的scsi总线: 找到scsi磁 ...

  7. c语言中#和##的用法

    一.一般用法 我们使用#把宏参数变为一个字符串,用##把两个宏参数贴合在一起. 用法: #include<cstdio> #include<climits> using nam ...

  8. LeetCode: 476 Number Complement(easy)

    题目: Given a positive integer, output its complement number. The complement strategy is to flip the b ...

  9. 《剑指offer》面试题13—O(1)时间删除链表结点

    题目:给定单向链表的头指针和某结点指针,实现函数在O(1)时间内删除指定节点. 思路:由于没有要删除结点(j结点)的前一个结点(i结点)指针,通常想法是从头开始遍历找到指定结点的前一个结点(i结点), ...

  10. JavaScript代码风格和分号使用问题

    1.推荐代码风格 JavaScript Standard Style  规定相对松散更多人使用此规范 Airbnb JavaScript Style  规定更严格但也没毛病 2.JavaScript代 ...