一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?
Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。

Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。

Sample Input

  1. abcde a3
  2. aaaaaa aa
  3. #

Sample Output

  1. 0
  2. 3
  3.  
  4. kmp裸题,不同的是不能重叠。
    不能重叠 j=0 重叠的话是 j=Next[j]
    比较好理解。因为不重叠就当前ij=0 重叠就是当前iNext[j],前面部分重叠(i之前的k个)
  5.  
  1. #include<stdio.h>
  2. #include<string.h>
  3. int Next[],n,m,tlen,plen;
  4. char t[],p[];
  5.  
  6. void prekmp() {
  7. int i,j;
  8. tlen=strlen(t);
  9. plen=strlen(p);
  10. j=Next[]=-;
  11. i=;
  12. while(i<plen) {
  13. while(j!=-&&p[i]!=p[j]) j=Next[j];
  14. if(p[++i]==p[++j]) Next[i]=Next[j];
  15. else Next[i]=j;
  16. }
  17. }
  18.  
  19. int kmp() {
  20. prekmp();
  21. int i,j,ans=;
  22. i=j=;
  23. while(i<tlen) {
  24. while(j!=-&&t[i]!=p[j]) j=Next[j];
  25. i++;j++;
  26. if(j>=plen) {
  27. ans++;
  28. j=;//不重叠
  29. }
  30. }
  31. return ans;
  32. }
  33.  
  34. int main() {
  35. while(~scanf("%s",t)) {
  36. if(t[]=='#') break;
  37. scanf("%s",p);
  38. printf("%d\n",kmp());
  39. }
  40. }

kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条的更多相关文章

  1. hdu2087 剪花布条

    剪花布条 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. 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 ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  5. 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 ...

  6. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  9. 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 ...

随机推荐

  1. [Python]python CGI脚本在apache服务器上运行时出现“Premature end of script headers”错误

    在测试自己的python CGI脚本时, 当html网页中的表单form内容传送到服务器python脚本时, 总是出现Premature end of script headers错误, 网页显示是服 ...

  2. JavaScript基本概念B - 关于方法

    方法也是对象 这个事需要反复强调.方法是 类型 Function 的对象,和其他对象一样,它也有方法. function gen() { return function ans(factor) { r ...

  3. 第十四章 Spring MVC的工作机制与设计模式(待续)

    Spring MVC的总体设计 Control设计 Model设计 View设计 框架设计的思考 设计模式解析之模版模式

  4. Centos 7.2 安装稳定版 nginx

    1. 创建适用于RHEL/CentOS系统的安装源文件,位置为: /etc/yum.repos.d/nginx.repo , 并写入以下内容: [nginx] name=nginx repo base ...

  5. java 多线程系列---JUC原子类(三)之AtomicLongArray原子类

    AtomicLongArray介绍和函数列表 在"Java多线程系列--“JUC原子类”02之 AtomicLong原子类"中介绍过,AtomicLong是作用是对长整形进行原子操 ...

  6. Linux-CentOS 学习的坎坷路 (一) 网络配置篇

    自己学习的地址:http://www.imooc.com/view/175 学到2.8章节,配置IP这一块,妈蛋,他直接跳过了,都不知道怎么配置,无奈,只能Search 先是找到配置IP的方法: ht ...

  7. 【263】Linux 添加环境变量 & 全局 shell 脚本

    Linux电脑添加环境变量 方法一:通过修改 profile 文件添加环境变量 1. 打开终端,输入[vi /etc/profile],如下所示,点击回车 [ocean@ygs-jhyang-w1 L ...

  8. madplay的使用方法

    管理madplay的主程序,包括播放,暂停播放,恢复播放,停止播放 system("madplay north.mp3 &");//利用system函数调用madplay播 ...

  9. C++ 私有构造函数的作用

    很多情况下要求当前的程序中只有一个object.例如一个程序只有一个和数据库的连接,只有一个鼠标的object.通常我们都将构造函数的声明置于public区段,假如我们将 其放入private区段中会 ...

  10. Codeforces 1107E (Vasya and Binary String) (记忆化,DP + DP)

    题意:给你一个长度为n的01串,和一个数组a,你可以每次选择消除一段数字相同的01串,假设消除的长度为len,那么收益为a[len],问最大的收益是多少? 思路:前两天刚做了POJ 1390,和此题很 ...