poj 2406 Power Strings【kmp】
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】的更多相关文章
- poj 2406 Power Strings【最小循环节】
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36926 Accepted: 15254 D ...
- poj 2406 Power Strings【字符串+最小循环节的个数】
Po ...
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- poj2406 Power Strings 【KMP】
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- poj 2406 Power Strings(KMP入门,next函数理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 37685 Accepted: 15590 D ...
- poj 2406 Power Strings(kmp应用)
题目链接:http://poj.org/problem?id=2406 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是 ...
- POJ 2406 Power Strings(KMP)
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- POJ 2406 Power Strings 简单KMP模板 strcmp
http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...
- poj 2406 Power Strings(kmp循环节)
题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如: a b ...
随机推荐
- android-----JNI中的log打印
1. 导入log头文件 在你使用的 .c/ .cpp 文件中 导入 log.h 头文件 #include<android/log.h> 2.在Android.mk 中 加上 LOCAL_L ...
- background-size使用参考指南
语法:background-size :[ <length> | <percentage> | auto ]{1,2} | cover | contain相关属性: backg ...
- 基于jquery 全选、反选、各行换色、单击行选中事件实现代码
<script language="javascript"> $(document).ready(function(){ //各行换色 $('table tr:odd' ...
- C# Backgroundworker(后台线程)的使用
namespace BackgroundWorkderPauseSample { public partial class MainForm : Form { BackgroundWorker wor ...
- [LeetCode] 038. Count and Say (Easy) (C++/Python)
索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 038. Cou ...
- ViewPagerTransforms
https://github.com/eltld/ViewPagerTransforms
- Redis实现消息的发布/订阅
利用spring-boot结合redis进行消息的发布与订阅: 发布: class Publish { private static String topicName = “Topic:chat”; ...
- STM32唯一身份识别ID(器件电子签名)的读取以及芯片Flash大小读取
每个STM32有一个独立的ID,这个ID可以用来: 产品唯一的身份标识的作用: ● 用来作为序列号(例如USB字符序列号或者其他的终端应用): ● 用来作为密码,在编写闪存时,将此唯一 ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- POJ2752 Seek the Name, Seek the Fame —— KMP next数组
题目链接:https://vjudge.net/problem/POJ-2752 Seek the Name, Seek the Fame Time Limit: 2000MS Memory Li ...