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 ...
随机推荐
- DAY10-python并发之IO模型
一 IO模型介绍 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问 ...
- 昨天的笔试题, StringBuffer
代码: public static void switchStr(StringBuffer x, StringBuffer y) { x.append(y); System.out.println(& ...
- 手动编译安装tmux
tmux的好处就不多说了,总之是多屏管理的神器.通常我们用系统通用的安装方式可以安装到tmux,但有时候,安装到的可能不是我们所需要的版本,又或者软件源里面没有带tmux.这个时候就需要手动编译安装了 ...
- FTP批量下载数据文件
包含ftp的命令脚本,建立临时文件. ::服务器连接信息 set username=root set password=root set ip=xxx.xxx.xxx.xxx set RemoteDi ...
- Ros疑问汇总
一.机器人描述文件三个: 机器人主体body文件: gazebo属性文件: 主文件 smartcar.urdf: 二.启动文件smartcar_display.rviz.launch:启动节点和模拟器 ...
- 算法Sedgewick第四版-第1章基础-024-M/M/1 queue
/****************************************************************************** * Compilation: javac ...
- 树莓派研究笔记(9)-- 树莓派SPI连接TFT屏幕
HDMI连接和树莓派专用连接的接口的屏幕都太贵了,为了节约成本,现在国内大多数还是TFT屏幕. 树莓派可以激活SPI接口,通过代码驱动TFT屏幕的显示.这样利用树莓派zero 打造小型的游戏平台可以大 ...
- 修改tomcat默认的编码方式
tomcat8以后默认编码格式是utf-8:7之前的都是iso8859-1 如果默认情况下,tomcat使用的的编码方式:iso8859-1 修改tomcat下的conf/server.xml文件 找 ...
- 数据结构 station
问题描述 一天,小 L 突然对列车的进出站问题产生了兴趣,如下图所示:列车只能从 A 进站,或从 B 出站.列车从 A 进站,进站顺序为 1, 2, 3, 4, 5列车从 B 出站,出站顺序为 5, ...
- Linux下管理员强行踢出用户的命令使用方法
Linux强制踢出用户命令: 一.输入w命令查看已登录用户信息 [root@KW_S01_192.168.1.106_A ~]# w 19:22:31 up 2:11, 3 users, loa ...