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 ...
随机推荐
- paramiko连接方式
链接方法: 方式一: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh. ...
- 初识Vue练习
<html lang="en"> <head> <meta charset="UTF-8"> <title>Ti ...
- oracle connect by用法篇 (包括树遍历)之一
1.基本语法 select * from table [start with condition1] connect by [prior] id=parentid 一般用来查找存在父子关系的数据,也就 ...
- 10-24C#基础--枚举
一.枚举 1.定义:在程序编写中,枚举同结构体是并列的,位于Class下面:枚举是常量的集合. enum meiju://枚举是常量的集合,一般冒号后面不指定数据类型 2.格式: enum meiju ...
- memset,memcpy,strcpy的使用与区别
1.memset 原型: extern void *memset(void *buffer, int c, int count); 功能: 把buffer所指内存区域的前count个字节设置成 ...
- 线程池的原理以及实现线程池的类ExecutorService中方法的使用
1.线程池:线程池就是就像一个容器,而这个容器就是用来存放线程的,且有固定的容量. 如果没有线程池,当需要一个线程来执行任务时就需要创建一个线程,我们设创建线程的时间为t1,执行线程的时间为t2,销毁 ...
- 100851K King’s Inspection
传送门 题目大意 给你一张图,求这张图的汉密尔顿回路. 分析 因为m≤n+20,所以如果存在回路一定是在一个环中加入了至多20条边.我们先考虑dfs,但我们发现如果出现图1这种情况就会是复杂度爆炸 图 ...
- 前端基础 之 jQuery
浏览目录 jQuery介绍 jQuery的优势 jQuery对象 jQuery内容 一.jQuery介绍 1.jQuery是一个轻量级的.兼容多浏览器的JavaScript库. 2.jQuery使用户 ...
- JavaWeb_反射
一个类有多个组成部分,例如:成员变量,方法,构造方法等.反射就是加载类,并解剖出类的各个组成部分. 编程时什么情况下才需要加载类,并解剖出累的各个组成部分呢? 反射是用来做框架的. 从配置文件中解读类 ...
- WebGoat系列实验Authentication Flaws
WebGoat系列实验Authentication Flaws Forgot Password Web应用经常给用户提供取回密码的功能,但是许多应用的实现策略实现的很差,用于验证用户的信息非常简单. ...