KMP入门(周期)
Description
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
ans=len/(len-fail[len]);
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; char s[];
int fail[];
int len; void get_fail(); int main()
{
while(scanf("%s",s+),s[]!='.')
{
len=strlen(s+);
get_fail();
int ans=;
//ÀûÓÃfail[len]
if(len%(len-fail[len])==)
ans=len/(len-fail[len]);
printf("%d\n",ans);
}
}
void get_fail()
{
memset(fail,,sizeof(fail));
fail[]=-;
for(int i=;i<=len;i++)
{
int p=fail[i-];
while(p>=&&s[p+]!=s[i])
p=fail[p];
fail[i]=p+;
//cout<<i<<" "<<fail[i]<<endl;
}
}
KMP入门(周期)的更多相关文章
- zstu.4194: 字符串匹配(kmp入门题&& 心得)
4194: 字符串匹配 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 206 Solved: 78 Description 给你两个字符串A,B,请 ...
- 题解报告:hdu 2087 剪花布条(KMP入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面 ...
- 转载 - kmp next函数 kmp的周期问题,深入了解kmp中next的原理
出处:http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html kmp next函数 kmp的周期问题,深入了解kmp中next的原理 ...
- hdu 1358 Period(KMP入门题)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1358 period KMP入门
Period 题意:一个长为N (2 <= N <= 1 000 000) 的字符串,问前缀串长度为k(k > 1)是否是一个周期串,即k = A...A;若是则按k从小到大的顺序输 ...
- KMP 入门
再次学习 \(\rm KMP\) 后不一样的理解. 一些概念 定义字符串 \(S\) 的真 前/后 缀为非自身的 前/后 缀. 定义字符串 \(S\) 的 \(border\) 为 \(S\) 的公共 ...
- KMP入门题目[不定期更新]
HDU 1711 Number Sequence(模板题) #include <cstdio> ; ; int N, M; int textS[MAXN]; int tarS[MAXL]; ...
- KMP入门(匹配)
Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M ...
- [HDU 1358]Period[kmp求周期]
题意: 每一个power前缀的周期数(>1). 思路: kmp的next. 每一个前缀都询问一遍. #include <cstring> #include <cstdio> ...
随机推荐
- PowerDesigner实用技巧小结(3)
PowerDesigner实用技巧小结(3) PowerDesigner 技巧小结 sqlserver数据库databasevbscriptsqldomain 1.PowerDesigner 使用 M ...
- C# 条形码 生成函数 (Code 128 标准
C# 条形码 生成函数 (Code 128 标准参考:GB/T 18347-2001) 最近在做单据打印,发现客户要求用到条形码,在网上找了,发现只有一些条形码的标准,但打出来发现根本不能扫,还要加某 ...
- ASP.NET线程与异步
什么是线程? 线程简单来说就是一种数据结构,用来管理这个程序的执行状态,其中包括 1.线程核心对象->寄存器的状态 2.线程环境块,是一块用户模式下的内存,包含线程的异常处理链的头部.线程的局部 ...
- ABAP ALV 颜色设置(行,列,单元格)
BCALV_EDIT_03 http://blog.sina.com.cn/s/blog_a87b19300102who3.html 关于ALV表格颜色,这种需求在项目中会经常用到. 列颜色 列的颜色 ...
- android获取mac地址方法
http://www.cnblogs.com/xioapingguo/p/4037513.html 网上找的,记录一下 public static String getMacAdress(){ Wif ...
- Spring Quartz结合Spring mail定期发送邮件
文件配置例如以下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- MVC4网站发布到windows server 2003服务器
在windows server 2003上部署MVC4的网站,需要进行以下工作 用VS2013新建项目 在创建项目的时候选择的矿建为.NET Framework4,然后选择[ASP.NET MVC4 ...
- [AngularJS] Reusable directive, require from parent controller
Glorious Directives for Our Navigation NoteWrangler navigation has now been broken into two parts: t ...
- IPVS
http://kb.linuxvirtualserver.org/wiki/IPVS_FULLNAT_and_SYNPROXY
- [016]转--C++拷贝构造函数详解
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员 ...