poj_2406 KMP寻找重复子串问题
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
#include <iostream>
#include <cstdio>
using namespace std;
char str[];
int next[];
int knext()
{
int mini=;
next[]=;
int i,j=;
for (i=;str[i]!='\0';i++)
{
if (str[i]==str[j]) j++;
else
{
while (j>&&str[j]!=str[i]) j=next[j-];
if (str[j]==str[i]) j++;
}
next[i]=j;
if (next[i]!=next[i-1]) mini=i-j;//当前失配,记录最新失配点。
}
if (i%(mini+)==)//如果重复母串根本不能构成总串,说明根本不是重复母串。
return i/(mini+);
else return ;
}
int main()
{
while (gets(str))
{
if (str[]=='.') break;
printf("%d\n",knext());
}
return ;
}
poj_2406 KMP寻找重复子串问题的更多相关文章
- poj 2406 Power Strings(kmp求一个串的重复子串)
题意:重复子串次数 思路:kmp #include<iostream> #include<stdio.h> #include<string.h> using nam ...
- POJ 1743 - Musical Theme 最长不重叠重复子串
题意: 给出一列数据,问你其中重复的最长连续子串的长度 但是有要求: 1. 长度至少为 5 . 2. 两串可以不相等,但两串每个对应位置的数字相减差值固定 (即 ...
- poj2406 连续重复子串
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41110 Accepted: 17099 D ...
- POJ 3693 Maximum repetition substring(连续重复子串)
http://poj.org/problem?id=3693 题意:给定一个字符串,求重复次数最多的连续重复子串. 思路: 这道题确实是搞了很久,首先枚举连续子串的长度L,那么子串肯定包含了r[k], ...
- 3. Longest Substring Without Repeating Character[M] 最大不重复子串
题目 Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【POJ 3693】Maximum repetition substring 重复次数最多的连续重复子串
后缀数组的论文里的例题,论文里的题解并没有看懂,,, 求一个重复次数最多的连续重复子串,又因为要找最靠前的,所以扫的时候记录最大的重复次数为$ans$,扫完后再后从头暴力扫到尾找重复次数为$ans$的 ...
- 【POJ 3261】Milk Patterns 可重叠的k次最长重复子串
可重叠的k次最长重复子串 #include<cstdio> #include<cstring> #include<algorithm> using namespac ...
- spoj687 后缀数组重复次数最多的连续重复子串
REPEATS - Repeats no tags A string s is called an (k,l)-repeat if s is obtained by concatenating k& ...
随机推荐
- php hash算法实现memcached分布式
一.概述Memcached和mysql一样,是一款客户端/服务器端(C/S)系统管理软件,有IP.端口,一旦启动,服务器就一直处于可用状态.Mysql是通过SQL语句管理“磁盘中”的文件,Memcac ...
- MySQL 如何使用 PV 和 PVC?【转】
本节演示如何为 MySQL 数据库提供持久化存储,步骤为: 创建 PV 和 PVC. 部署 MySQL. 向 MySQL 添加数据. 模拟节点宕机故障,Kubernetes 将 MySQL 自动迁移到 ...
- 第3节 sqoop:7、通过java代码远程连接linux执行shell命令
数据库的数据同步软件sqoop 数据同步 关系型数据库到大数据平台 任务:sqoop 是批量导入数据太慢,如何做到实时的数据同步 实时的数据同步工具: canal 阿里开源的一个数据库数据实时同步的软 ...
- 手机连接jmeter录制脚本测试
1.准备条件 电脑安装好jmeter,准备好一个手机 注意: 电脑和手机连接的网络要一致 手机设置代理协议前要先进入想要抓取的网站: http://39.107.96.138:3000/ 2.jmet ...
- Linux-kernel-timeline
Linux kernel Protocol Location HTTP https://www.kernel.org/pub/ GIT https://git.kernel.org/ RSYNC rs ...
- DCGAN增强图片数据集
DCGAN增强图片数据集 1.Dependencies Python 3.6+ PyTorch 0.4.0 numpy 1.14.1, matplotlib 2.2.2, scipy 1.1.0 im ...
- 吴裕雄--天生自然java开发常用类库学习笔记:SortedSet接口
import java.util.SortedSet ; import java.util.TreeSet ; public class TreeSetDemo05{ public static vo ...
- Spring入门之三-------SpringIoC之Scopes
一.singleton和prototype public class Bean1 { public Bean1() { System.out.println(this.getClass().getSi ...
- ORIGIN(起源属性)路由起源骗术
ORIGIN(起源属性)配置: ①:抓取感兴趣流量——prefix.access ②:创建route-map 流量地图——permit 10 ③:匹配感兴趣流量——match ④:设置起源属性——se ...
- 控制数据的小数位数 java / js
//java一般控制格式都是通过 DecimalFormat 来控制的.下边是个例子. import java.text.DecimalFormat; public class ControlBit ...