Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 45005   Accepted: 18792

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


只需要求n的错位部分n-f[n]是不是循环节
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+;
int n,f[N];
char p[N];
int main(){
int cas=;
while(true){
scanf("%s",p);
n=strlen(p);
if(p[]=='.') break;
f[]=f[]=;
for(int i=;i<n;i++){
int j=f[i];
while(j&&p[j]!=p[i]) j=f[j];
f[i+]=p[j]==p[i]?j+:;
}
if(n%(n-f[n])==) printf("%d\n",n/(n-f[n]));
else printf("1\n");
}
}

POJ2406Power Strings[KMP 失配函数]的更多相关文章

  1. poj2406 Power Strings(kmp失配函数)

    Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 39291 Accepted: 16315 Descr ...

  2. POJ--2406Power Strings+KMP求字符串最小周期

    题目链接:点击进入 事实上就是KMP算法next数组的简单应用.假设我们设这个字符串的最小周期为x 长度为len,那么由next数组的意义,我们知道len-next[len]的值就会等于x.这就是这个 ...

  3. POJ2406-Power Strings(kmp循环节)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 31111   Accepted: 12982 D ...

  4. POJ1961[KMP 失配函数]

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 16776   Accepted: 8077 Descripti ...

  5. poj2406--Power Strings(kmp:求循环串的次数)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33163   Accepted: 13784 D ...

  6. HDU--1358--KMP算法失配函数getfail()的理解--Period

    /* Name: hdu--1358--Period Author: 日天大帝 Date: 20/04/17 10:24 Description: 长度/向后移动的位数 = 出现的次数 kmp其实匹配 ...

  7. POJ 2406Power Strings(KMP)

    POJ 2406 其实就是一个简单的kmp应用: ans = n % (n - f[n]) == 0 ? n / (n - f[n]) : 1 其中f是失配函数 //#pragma comment(l ...

  8. LightOJ 1268 Unlucky Strings (KMP+矩阵快速幂)

    题意:给出一个字符集和一个字符串和正整数n,问由给定字符集组成的所有长度为n的串中不以给定字符串为连续子串的有多少个? 析:n 实在是太大了,如果小的话,就可以用动态规划做了,所以只能用矩阵快速幂来做 ...

  9. 转载 - kmp next函数 kmp的周期问题,深入了解kmp中next的原理

    出处:http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html kmp next函数 kmp的周期问题,深入了解kmp中next的原理 ...

随机推荐

  1. C++11之lambda表达式

    lambda表达式源于函数式编程的概念,它可以就地匿名定义目标函数或函数对象,不需要额外写一个命名函数或者函数对象.lambda表达式的类型在C++11中被称为"闭包类型",也可以 ...

  2. C++11之std::function和std::bind

    std::function是可调用对象的包装器,它最重要的功能是实现延时调用: #include "stdafx.h" #include<iostream>// std ...

  3. 在DirectShow中支持DXVA 2.0(Supporting DXVA 2.0 in DirectShow)

    这几天在做dxva2硬件加速,找不到什么资料,翻译了一下微软的两篇相关文档.并准备记录一下用ffmpeg实现dxva2,将在第三篇写到.这是第二篇.,英文原址:https://msdn.microso ...

  4. [moka同学笔记]五、Yii2.0课程笔记(魏曦老师教程)[审核功能]

  5. 【夯实PHP基础】PHP的date函数

    本文地址 原文地址 提纲: 1. 引言 2. 代码示例 3. 参考资料 1. 引言 今天看到一段代码 $timeNew = date('n月j日', strtotime($oldTime)); 感觉有 ...

  6. 帆布指纹识别(canvas fingerprinting)

    广告联盟或许网站运营者都希望能够精准定位并标识每一个个体,通过对用户行为的分析(浏览了哪些页面?搜索了哪些关键字?对什么感兴趣?点了哪些按钮?用了哪些功能?看了哪些商品?把哪些放入了购物车等等),为用 ...

  7. jQuery中的事件处理

    1.页面载入完毕响应事件所谓页面载入完毕是指DOM元素载入就绪了,能够被读取和操作了.①jQuery中的$(doucument).ready()事件ready(fn)是jQuery事件模块中最重要的一 ...

  8. 【grunt第一弹】30分钟学会使用grunt打包前端代码

    前言 以现在前端js激增的态势,一个项目下来几十个js文件轻轻松松对于复杂一点的单页应用来说,文件上百简直是家常便饭,那么这个时候我们的js文件应该怎么处理呢?另外,对于css文件,又该如何处理呢?? ...

  9. iOS之清除缓存

    //清除缓存按钮的点击事件 - (void)putBufferBtnClicked:(UIButton *)btn{ CGFloat size = [self folderSizeAtPath:NSS ...

  10. React Native环境配置和简单使用

    # 前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会 ...