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 ...
随机推荐
- css3弹性布局语法全解
本文介绍css3弹性布局的语法 html布局 <div class="box"> <div class="item">1</div ...
- 类型:sqlserver;问题:版本;结果:sqlserver版本区分
LocalDB (SqlLocalDB)LocalDB 是 Express 的一种轻型版本,该版本具备所有可编程性功能,但在用户模式下运行,并且具有快速的零配置安装和必备组件要求较少的特点.如果您需要 ...
- mysql如何开启远程连接(默认未开启,即使密码正确,仍然无法访问)
mysql如何开启远程连接 | 浏览:1846 | 更新:2015-03-11 20:19 1 2 3 4 5 6 分步阅读 百度经验:jingyan.baidu.com 大家在公司工作中,经常会遇到 ...
- 链接ssh失败问题
Starting sshd:/var/empty/sshd must be owned by root and not group or world-writable. ...
- JavaScipt——Windows.document对象
四中选择器:class ,id , name , 标签 通过选择器获取对象: document.getElementById(''); -- id选择器 ...................... ...
- Qt测试计算时间
博客转载自:https://blog.csdn.net/lg1259156776/article/details/52325508 一.标准C和C++都可用 1. 获取时间用time_t time( ...
- HTML和CSS入门教程
慕课网上面的HTML+CSS基础课程感觉非常适合入门.
- 前端基础 之 jQuery
浏览目录 jQuery介绍 jQuery的优势 jQuery对象 jQuery内容 一.jQuery介绍 1.jQuery是一个轻量级的.兼容多浏览器的JavaScript库. 2.jQuery使用户 ...
- Entity Framework Tutorial Basics(5):Create Entity Data Model
Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...
- 打印sql语句
root->trace hibernate->trace ,然后,改配置 全文搜索:show_sql,将所有的show_sql改为true. 这样,就会显示sql语句了.