Power Strings
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 41252   Accepted: 17152

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.

题意:

给出的一个字符串某个字串链接N次得出的,求最大N;

思想:

KMP匹配算法之next[];模式串结尾指针回溯最小移动次数即最小字串长度,N=s.length%(s.length-next[s.length]);

#include <stdio.h>
#include <string.h>
char s[1000005];
int num[1000005];
int main()
{
while(scanf("%s",s),s[0]!='.')
{
int j=-1;
num[0]=-1;
int n=strlen(s);
for(int i=0; i<n;)
{
if(j==-1||s[i]==s[j])num[++i]=++j;
else j=num[j];
}
if(n%(n-num[n])==0)
printf("%d\n",n/(n-num[n]));
else printf("1\n");
}
return 0;
}

POJ 2406:Power Strings的更多相关文章

  1. 【poj 2406】Power Strings 后缀数组DC3模板 【连续重复子串】

    Power Strings 题意 给出一个字符串s,求s最多由几个相同的字符串重复而成(最小循环节的重复次数) 思路 之前学习KMP的时候做过. 我的思路是:枚举字符串的长度,对于当前长度k,判断\( ...

  2. 【POJ 2406】Power Strings 连续重复子串

    看的<后缀数组——处理字符串的有力工具>这篇论文,在那里这道题是用后缀数组实现的,复杂度为$O(nlogn)$,很明显长度为$2×10^6$的数据会TLE,所以必需得用复杂度为$O(n)$ ...

  3. 【POJ 2406】Power Strings(KMP循环节)

    终于靠着理解写出KMP了,两种KMP要代码中这种才能求循环节.i-next[i]就是循环节. #include<cstdio> #define N 1000005 char s[N]; i ...

  4. 【POJ 2406】 Power Strings

    [题目链接] 点击打开链接 [算法] KMP 如果字符串中存在循环节,则next[len] = (循环节个数 - 1) * 循环节长度 循环节个数 = len / (len - next[len]) ...

  5. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  6. POJ 2109 :Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18258   Accepted: ...

  7. 【TOJ 2406】Power Strings(KMP找最多重复子串)

    描述 Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc& ...

  8. POJ2406:Power Strings——题解

    http://poj.org/problem?id=2406 就是给一个串,求其循环节的个数. 稍微想一下就知道,KMP中nxt数组记录了所有可与前面匹配的位置. 那么如果我们的循环节长度为k,有n个 ...

  9. POJ 3096:Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6258   Accepted: 407 ...

随机推荐

  1. Python学习总结5:数据类型及转换

    Python提供的基本数据类型主要有:整型.浮点型.字符串.列表.元组.集合.字典.布尔类型等等. Python可以用一些数据类型函数,直接进行转换: 函数                       ...

  2. Nopi .net下面的Excel第三方dll

    相关参考资料:1.npoi官网:http://npoi.codeplex.com/2.用NPOI操作EXCEL--插入图片:  http://www.cnblogs.com/atao/archive/ ...

  3. 今天遇到的一个问题(windows的ssh客户端连接不到虚拟机Ubuntu)

    今天比较郁闷,想用windows上的ssh客户端连接虚拟机中的Ubuntu. 但是死活连不上,之前是能脸上的,所以比较郁闷. 我首先在windows上ping Ubuntu的ip地址,竟然发不了数据包 ...

  4. bzoj2743 [HEOI2012]采花

    做法是每个询问先算出询问区间中花的种类减去区间中只有一朵花的花的种类,这两个子问题都不算难,具体看代码吧.询问可以离线处理,用树状数组维护,复杂度O(nlogn). 不知道是想的复杂了还是打的太low ...

  5. ligerui_ligerTree_002_利用JavaScript代码配置ligerTree节点

    利用JavaScript代码配置ligerTree节点: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: <%@ p ...

  6. paper 82:边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)

    不同图像灰度不同,边界处一般会有明显的边缘,利用此特征可以分割图像.需要说明的是:边缘和物体间的边界并不等同,边缘指的是图像中像素的值有突变的地方,而物体间的边界指的是现实场景中的存在于物体之间的边界 ...

  7. 夺命雷公狗jquery---3普通选择器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. zw版【转发·台湾nvp系列例程】halcon与delphi系列例程

    zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...

  9. c# 操作xml题目

    download! 1.新建一个文本文件,命名为:projects.txt. 2.将后缀名改为projects.xml.  3.用记事本编辑该文件.使用utf-8编码.内容如下: <?xml v ...

  10. 视频处理控件TVideoGrabber如何重新编码视频

    TVideoGrabber中可以对音频.视频剪辑进行重新编码剪辑,多的朋友知道这个功能更点,但是具体操作上还是不是很熟悉,这里总结一下,主要步骤如下: 1.通过指定开始和停止的时间,可以简单的剪辑视频 ...