hdu 1686 Oulipo
来源:互联网 发布:bim软件分类 编辑:程序博客网 时间:2024/05/17 21:52
题目:
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686
题意:
输入t,是测试组数。每组测试,依次输入 字符串s1和s2。求出s2中s1的个数,可以有重叠。
思路:
KMP算法。
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;char s1[10010],s2[1000010];int next[10010];int len1,len2;void get_nextval(char s[],int len){ int i,j; i = -1; j = 0; next[0] = -1; while(j<len) { if(i == -1 || s[i] == s[j]) { j++; i++; next[j] = i; } else i = next[i]; }}int KMP(int m,int n)//m是s1串的长度,n是s2串的长度{ int i=0,j=0; int num=0;//s2中s1的个数,和hdu 2087不同的是,s2中的s1可以有重叠(关键看s1的next数组) while(i<n) { if(s1[j] == s2[i] || j==-1) { i++;j++; if(j==m) { num++; j=next[j]; } } else j=next[j]; } return num;}int main(){ //freopen("input.txt","r",stdin); int t; cin>>t; getchar(); while(t--) { gets(s1); gets(s2); len1 = strlen(s1); len2 = strlen(s2); get_nextval(s1,len1); cout<<KMP(len1,len2)<<endl; } return 0;}
0 0
- HDU 1686 Oulipo (kmp)
- hdu 1686 Oulipo
- hdu 1686 Oulipo
- hdu 1686 Oulipo
- hdu 1686 kmp Oulipo
- hdu 1686 Oulipo
- KMP hdu-1686-Oulipo
- HDU 1686 Oulipo
- Hdu 1686 Oulipo[kmp]
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo
- HDU-1686-Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- hdu 1686 Oulipo(KMP)
- HDU - 1686 Oulipo
- HDU 1686 Oulipo (KMP)
- HDU 1686 Oulipo(KMP)
- HDU 1686 Oulipo - KID
- MATLAB小波图像分解
- union关键字
- error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”
- 5/7随笔 + 暑假计划
- [BZOJ1071][SCOI2007][堆]组队
- hdu 1686 Oulipo
- [Accessibility] Missing contentDescription attribute on image
- java覆盖TXt文件中内容
- OpenCV的编程环境安装指南
- flash
- java JSP快速入门
- SVN常用命令
- uva 10400 Game Show Math
- IOS编码GB2312转UTF-8