kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。
Sample Input
abcde a3
aaaaaa aa
#
Sample Output
0
3 kmp裸题,不同的是不能重叠。
不能重叠 j=0 重叠的话是 j=Next[j]
比较好理解。因为不重叠就当前i和j=0 重叠就是当前i和Next[j],前面部分重叠(i之前的k个)
#include<stdio.h>
#include<string.h>
int Next[],n,m,tlen,plen;
char t[],p[]; void prekmp() {
int i,j;
tlen=strlen(t);
plen=strlen(p);
j=Next[]=-;
i=;
while(i<plen) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
if(p[++i]==p[++j]) Next[i]=Next[j];
else Next[i]=j;
}
} int kmp() {
prekmp();
int i,j,ans=;
i=j=;
while(i<tlen) {
while(j!=-&&t[i]!=p[j]) j=Next[j];
i++;j++;
if(j>=plen) {
ans++;
j=;//不重叠
}
}
return ans;
} int main() {
while(~scanf("%s",t)) {
if(t[]=='#') break;
scanf("%s",p);
printf("%d\n",kmp());
}
}
kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条的更多相关文章
- hdu2087 剪花布条
剪花布条 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- unittest添加测试用例方法
1. suite=unittest.TestLoader().loadTestsFromTestCase(changedTestHJ)unittest.TextTestRunner(verbosity ...
- C Primer Plus学习笔记(一)- C语言概述
从一个简单的C语言程序开始 #include <stdio.h> /*这是一个简单的C语言程序*/ //注释 int main(void) { int num; num = 1; prin ...
- taskkill /f /t /im processName
/*@echo off */taskkill /f /t /im WINWORD.exetaskkill /f /t /im nginx.exetaskkill /f /t /im w3wp.exet ...
- SQLServer SDK
https://www.cnblogs.com/Leo_wl/p/3451865.html 回到目录 SQLSERVER一些公用DLL的作用解释 如果你的SQLSERVER安装在C盘的话,下面的路径就 ...
- java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory报错springmvc
转自:https://blog.csdn.net/qq_41879385/article/details/82892555 下面是错误信息:java.lang.ClassNotFoundExcepti ...
- js兼容事件
//浏览器检测(function () { window.sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.ma ...
- python爬虫(8)--Xpath语法与lxml库
1.XPath语法 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历.XPath 是 W3C XSLT 标准的主要元素,并且 XQuery ...
- close、flush、read、readline、seek、tell、truncate、write的使用
1.close关闭文件 f1= open("ha.log","r+",encoding="utf-8") data = f1.read() ...
- HDU 6162 树链剖分
题意:给你一颗树,每个节点有有一个权值,每次询问从x到y的最短路上权值在c到d之间的所有的点的权值和是多少. 思路:肯定要用树剖,因为询问c到d之间这种操作树上倍增很难做,但是用其它数据结构可以比较好 ...
- 解决eclipse的source not found change at.
eclise快捷键F3跳转到类的实现方法,出现如图所示问题:source not found change atttached source.点击下图红圈,Change Attached Sou ...