F - Power Strings

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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.
 
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define maxn 10010000
using namespace std;
char p[maxn];
int next[maxn],len;
int kmp(){
int i=,j=-;
next[]=-;
while(i<len){
if(j==-||p[i]==p[j]) next[++i]=++j;
else j=next[j];
}
}
int main()
{
while(scanf("%s",p)!=EOF&&p[]!='.'){
len=strlen(p);
kmp();
if(len%(len-next[len]))printf("1\n");
else printf("%d\n",len/(len-next[len]));
}
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. KMP + 求最小循环节 --- POJ 2406 Power Strings

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

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

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

  7. poj 2406 Power Strings kmp算法

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

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

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

  9. poj 2406 Power Strings(KMP变形)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 D ...

随机推荐

  1. Sharepoint 2013 开启App和配置App

    在任何站点中,点Add App,然后点Sharepoint Store,如果没有Enable apps,打开app store的时候出出现错误: Sorry, apps are turned off. ...

  2. Android根据APP包名启动应用

    public void openApp(String packageName, Context context) { PackageManager packageManager = context.g ...

  3. AOP这些应用场景(交叉业务)

    1.统计某个方法的性能,可以在每个业务方法执行前后 记录方法执行的当前时间,执行后的时间-执行前的时间= 方法执行时间.  这样就可以在开发过程中(项目未交付给客户前)统计程序的性能. 2.安全 ,权 ...

  4. android 进程间通信---Service Manager(2)

    关于servicemanager的设计: 还是这张结构图,由于ProcessState & IPCThreadState是与binder deriver交互的, 所以对于client端来说Bp ...

  5. Eclipse Svn 取消某些文件或文件夹的版本控制

    SVN提交时,我们有时候需要将一些文件忽略掉,例如:maven项目中的target文件夹,可以将这些文件或文件夹设置成ignore来忽略这些文件或文件夹 1. 将文件夹或文件从Eclipse中删除.记 ...

  6. PS网页设计教程XXIX——如何在PS中设计一个画廊布局

    作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...

  7. Web Application Project is configured to use IIS. Unable to access the IIS metabase.(配置为使用IIS Web应用程序xxxx项目。无法访问IIS元数据库。)

    这几天重装系统,装了win10,居然用vs2013打开项目出现下面这个提示错误,搞了很久才知道原因: Even though I am an administrator on the machine, ...

  8. 大型文档源文件拆分编辑编译\include{filename}

    大型文档,如果把所有的文字都录入在同一个.tex文件中,那个文件的体积是不可估量的,文件的结构式混乱不堪的,文字的定位也是令人头疼的.幸亏latex提供了结构化的处理命令---include. 命令\ ...

  9. MSDE简介

    MSDE的全程是Microsoft SQL Server Desktop Engine,它是一个基于 SQL Server 核心技术构建的数据引擎.MSDE 2000 支持单处理器和双处理器,是面向小 ...

  10. Excel scientific notation issue

        This is a known issue, you can find more in internet. Excel will treat text(can display with num ...