hdu 2087 kmp】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=2087 算是模板题吧,找到一个子串之后将模板串指针归零否则会重复计算. #include<bits/stdc++.h> using namespace std; ]; ],t[]; void kmp() { int szs=strlen(s),szt=strlen(t),i,j,k; nex[]=nex[]=; ;i<szt;++i) { j=nex[i]; while(j&&t[i]!…
题意: 用两个字符串分别表示布条和图案,问能从该布条上剪出多少这样的图案. 分析: 毫无疑问这也是用KMP匹配,关键是一次匹配完成后,模式串应该向后滑动多少. 和上一题 HDU 1686 不同,两个图案肯定不能在母串中有交叉的部分,所以当匹配成功一次后,应当滑动整个模式串的长度. 和上一题比,代码几乎不变,只是 j = next[j]; 变为 j = 0; #include <cstdio> #include <cstring> + ; char p[maxn], q[maxn];…
s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<math.h> #include<queue> using namespace std; char s[1005]; char t[1005]; int nextt[1005]; void makenext(const ch…
1.HDU 2087 2.题意:一个主串,一个子串,求子串在主串里出现了几次. 3.总结:看了题解,还是不太懂.. //#include<iostream>#include<cmath>#include<queue>#include<algorithm> //不明白为什么加上这些头文件就Compilation Error #include<cstring> #include<cstdio> using namespace std; #…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2087 KMP匹配数—— AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <vector> #include <list…
HDU 2087 剪花布条(字符串匹配,KMP) Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input 输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样.花纹条和小饰条不会超过1000个字符长.如果遇见#字符,则不再进行工作. Output 输出能从花纹布中剪出的最多小饰条个数…
剪花布条 HDU - 2087 要求各个匹配出来的子串不重叠的kmp.实际上直接贪心从前往后找,每找到一个就把当前j标为0即可.(一般kmp是标为f[j]) #include<cstdio> #include<cstring> ]; ]; ]; int m,n; void getf() { ,j=f[]=-; while(i<m) { &&s[i]!=s[j]) j=f[j]; i++;j++; f[i]=s[i]==s[j]?f[j]:j; } } int…
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; ; ; char T[MAX_N]; char p[MAX_M]; int f[MAX_M]; int n,m; void getfail(){ f[] = f[] = ; ;i&l…
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len]-len的差即是循环部分的长度. 这个是重点.这个题目自己开始没有想明白,看的博客,推荐这个. 代码实现 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?   Input 输入中含有一些数据,分别是成对出现…