hdu2087(剪花布条) KMP算法
来源:互联网 发布:淘宝客厅装饰物 编辑:程序博客网 时间:2024/06/05 07:03
剪花布条
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22422 Accepted Submission(s): 14036
Problem Description
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?
Input
输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。
Output
输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。
Sample Input
abcde a3
aaaaaa aa
#
Sample Output
0
3
#include <bits/stdc++.h>using namespace std;char str1[12345],str2[12345];int nex[12345];int l1,l2;void get_next(){ int i=1; int j=0; nex[1]=0; while(i<=l2){ if(str2[i]==str2[j] || j==0){ i++; j++; nex[i]=j; } else { j=nex[j]; } } return;}int KMP(){ int i=1; int j=1; int cnt=0; while(i<=l1){ if(str1[i]==str2[j] || j==0){ i++; j++; } else { j=nex[j]; } if(j>l2){ cnt++; j=1; } } return cnt;}int main(){ while(~scanf("%s",str1+1)){ if(str1[1]=='#'){ return 0; } scanf("%s",str2+1); l1=strlen(str1+1); l2=strlen(str2+1); get_next(); printf("%d\n",KMP()); } return 0;}
阅读全文
0 0
- HDU2087-剪花布条(KMP算法)
- hdu2087(剪花布条) KMP算法
- hdu2087剪花布条(kmp)
- hdu2087 剪花布条(KMP)
- hdu2087 剪花布条(KMP)
- hdu2087剪花布条(kmp)
- hdu2087 剪花布条(简单KMP)
- hdu2087 剪花布条(kmp)
- hdu2087 剪花布条--KMP
- HDU2087 剪花布条 [KMP]
- hdu2087 剪花布条 KMP
- hdu2087 剪花布条 kmp
- hdu2087剪花布条[KMP]
- hdu2087 剪花布条【kmp】
- HDU2087--剪花布条 (KMP)
- 数据结构之KMP算法---hdu2087---剪花布条
- hdu2087 剪花布条(kmp基础变形)
- HDU2087-剪花布条-KMP模板
- gitlub私服的搭建
- ImportError: No module named cv2 报错处理
- 最长递增子序列个数
- angular入门2
- odbccp32.lib(dllload.obj) : error LNK2019: __imp___vsnprintf,该符号在函数 _StringVPrintfWorkerA@20 中被引用
- hdu2087(剪花布条) KMP算法
- 基于MFC的五子棋应用(三)
- 面向对象中的类和接口的理解
- 36. Valid Sudoku
- vue2.0 中事件处理心得
- Saruman's Army
- angular入门3
- 开发软件下载资源
- angular入门4