poj 2406

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 题目大意 :
  
  此题就可以借助 kmp 的 next数组,因为 next 数组所表示的意义就是当前位置前面的串的最长公共前后缀,所以最后一位中的 next 所存的值就表示其前面的前缀的最长公共部分 是多少 ,用总的长度减去前缀的长度 ,就得出了最小回文的串的长度。 代码示例 :
/*
* Author: ry
* Created Time: 2017/10/5 7:29:46
* File Name: 1.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
#include <map>
using namespace std;
const int eps = 1e6+5;
#define ll long long char s[eps];
int next[eps];
int len; void getnext(){
int i = 0, j = -1;
next[0] = -1;
while (i != len){
if (j == -1 || s[i] == s[j]){
i++;
j++;
next[i] = j;
}
else j = next[j];
}
} int main() { while (gets(s) != NULL){
if (s[0] == '.') break;
len = strlen(s);
getnext();
int ff = len - next[len];
if ((len - ff) % ff == 0) printf("%d\n", len/ff);
else printf("1\n");
} return 0;
} /*
sadjkghrfkjashioawruiofhasjklryqwodhasnkbfgakjsrhoqwuiyeaskjbtrjksa
*/

kmp-最小子串回文次数的更多相关文章

  1. HDU6599:求本质不同的子串(回文串)长度及数量

    目录 hdu6599题意: manacher+后缀自动机+倍增 \(O(nlog(n))\) manacher+后缀数组+二分 \(O(nlog(n))\) 回文树(回文自动机) \(O(n)\) @ ...

  2. 1159 Palindrome(最小插入回文串)

    标题效果 定的字符串长度的串和内容.中的字符可以在任何位置被插入.它至少需要为数字,这使得编程回文串串. 回文序列从左至右,从右到左和读取相同. 例如. aaaacbbbb它是一个回文串 aaab前面 ...

  3. 阿里天池的新任务(简单)(KMP统计子串出现的次数)

    阿里“天池”竞赛平台近日推出了一个新的挑战任务:对于给定的一串 DNA 碱基序列 tt,判断它在另一个根据规则生成的 DNA 碱基序列 ss 中出现了多少次. 输出格式 输出一个整数,为 tt 在 s ...

  4. HDU 1686 Oulipo【kmp求子串出现的次数】

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  5. hdu 2087剪花布条 (KMP入门 子串出现的次数和子串个数)

    剪花布条 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. 51Nod 1089 最长回文子串 V2 —— Manacher算法

    题目链接:https://vjudge.net/problem/51Nod-1089 1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值:  ...

  7. 算法:Manacher,给定一个字符串str,返回str中最长回文子串的长度。

    [题目] 给定一个字符串str,返回str中最长回文子串的长度 [举例] str="123", 1 str="abc1234321ab" 7 [暴力破解] 从左 ...

  8. 洛谷——P1609 最小回文数

    题目描述 回文数是从左向右读和从右向左读结果一样的数字串. 例如:121.44 和3是回文数,175和36不是. 对于一个给定的N,请你寻找一个回文数P,满足P>N. 满足这样条件的回文数很多, ...

  9. 洛谷—— P1609 最小回文数

    https://www.luogu.org/problemnew/show/1609 题目描述 回文数是从左向右读和从右向左读结果一样的数字串. 例如:121.44 和3是回文数,175和36不是. ...

随机推荐

  1. CF351E Jeff and Permutation

    CF351E Jeff and Permutation 贪心好题 考虑每个对能否最小化贡献和 先不考虑绝对值相同情况 发现,对于a,b假设|a|<|b|,那么有无贡献只和b的正负有关!如果a在b ...

  2. VMware虚拟机安装Windows2003操作教程

    1.下载好以下三个文件: 2.选择VMware安装包,跟随指令安装好后,打开: 3.选择"创建新的虚拟机"后,选择"安装光盘映像文件(iso)",点击浏览载入. ...

  3. Mockito -- 入门篇

    Mockito是一种mock工具/框架.我理解EasyMock有点过时了,Mockito是现在比较流行的. 什么是mock?说的直白一点,大家都知道unit test应该是尽可能独立的.对一个clas ...

  4. js实现bind

    Function.prototype.bind=function(ctx,...lastArgs){ let self=this return (...laterArgs)=>self.appl ...

  5. ZOJ3537 Cake

    ZOJ3537 Cake 传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题意: 给你几何形状的蛋糕,你需要 ...

  6. linux 搭建jenkins

    一.什么是持续集成? (1)Continuous integration(CI) 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员至少集成一次,也就意味着每天可能会发生多次集 ...

  7. 网易Java高级开发课程随笔

    java学习也有6个月之久,记录下课程相关知识点,目前我还没有掌握,so仅作技术点记录 鉴于在.NET上我封装了一套开发框架,虽去年按.NET封装的思路自己也弄了个java开发框架,还是感觉对java ...

  8. Appium中使用相对路径定位元素Xpath

    1.若页面该元素没有ID 2.找出该元素父类,并拷贝出父类的class(类名)和ID 3.点击搜索图标,进行查找 selector内容://android.widget.LinearLayout[@r ...

  9. maven parent 与 import 的区别

    在 maven 配置文件 pom.xml 中可以 引入 <parent>,方式如下(举例是 spring-boot-starter-parent 中的继承关系)   <parent& ...

  10. vue递归组件 (树形控件 )

    首先我们要知道,既然是递归组件,那么一定要有一个结束的条件,否则就会使用组件循环引用,最终出现“max stack size exceeded”的错误,也就是栈溢出.那么,我们可以使用v-if=&qu ...