kmp,根据next数组的性质如果有答案的话就是n/(n-(ne[n]+1)),否则是1

搬来打算用SA后来发现必须用DC3就没写

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1000005;
int n,ne[N];
char s[N];
int main()
{
while(scanf("%s",s)&&s[0]!='.')
{
n=strlen(s);
ne[0]=-1;
for(int i=1,j=-1;i<n;i++)
{
while(j!=-1&&s[i]!=s[j+1])
j=ne[j];
if(s[i]==s[j+1])
j++;
ne[i]=j;
}
ne[n]=ne[n-1]+1;
if(n%(n-ne[n])==0)
printf("%d\n",n/(n-ne[n]));
else
puts("1");
}
return 0;
}

poj 2406 Power Strings【kmp】的更多相关文章

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

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

  2. poj 2406 Power Strings【字符串+最小循环节的个数】

                                                                                                      Po ...

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

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

  4. poj2406 Power Strings 【KMP】

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

  5. poj 2406 Power Strings(KMP入门,next函数理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37685   Accepted: 15590 D ...

  6. poj 2406 Power Strings(kmp应用)

    题目链接:http://poj.org/problem?id=2406 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是 ...

  7. POJ 2406 Power Strings(KMP)

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

  8. POJ 2406 Power Strings 简单KMP模板 strcmp

    http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...

  9. poj 2406 Power Strings(kmp循环节)

    题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如:      a    b  ...

随机推荐

  1. JavaScript与Java通信

    1.WebView中JavaScript调用Android程序中Java: 使用WebView类中的addJavascriptInterface()方法,能够使用它扩展嵌入式浏览器内的DOM(文档对象 ...

  2. Office转SWF的一些感想(Office2007和Office2010)

    Office2007需要借助SaveAsPDFandXPS的插件完成,Office2010可以直接兼容. Office2PDF主要采用的是 Microsoft.Office.Interop的方式进行, ...

  3. Apatch常用的commons工具包介绍

    1.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...

  4. Intel processor brand names-Xeon,Core,Pentium,Celeron----Pentium

    http://en.wikipedia.org/wiki/Pentium Pentium From Wikipedia, the free encyclopedia     This article ...

  5. HDU 3039 Go Home

    今天本来解决的很好,本来可以不聊那么结束,但是我想更完美一点,多聊几句,谁知道就聊了很长时间,很傻逼.耽误了时间! /***************************************** ...

  6. RC4算法的Python实现详注

    刚对RC4算法进行了学习,网上发现https://ju.outofmemory.cn/entry/46753 中作者展示了RC4的python实现,但代码缺乏注释,较为晦涩,因此本文对部分代码进行了注 ...

  7. hihocode #1388 : Periodic Signal NTT

    #1388 : Periodic Signal   描述 Profess X is an expert in signal processing. He has a device which can ...

  8. HBase2.0新特性之In-Memory Compaction

    In-Memory Compaction是HBase2.0中的重要特性之一,通过在内存中引入LSM结构,减少多余数据,实现降低flush频率和减小写放大的效果.本文根据HBase2.0中相关代码以及社 ...

  9. AMQP 0-9-1 Model Explained Why does the queue memory grow and shrink when publishing/consuming? AMQP和AMQP Protocol的是整体和部分的关系 RabbitMQ speaks multiple protocols.

    AMQP 0-9-1 Model Explained — RabbitMQ http://next.rabbitmq.com/tutorials/amqp-concepts.html AMQP 0-9 ...

  10. HDU 5627Clarke and MST

    Clarke and MST Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...