POJ 3461 Oulipo (简单kmp)
来源:互联网 发布:我好想你网络歌手 编辑:程序博客网 时间:2024/05/19 15:20
题目类型 kmp
题目意思
问一个最长 10000 的串在一个最长 100 0000 的串中出现了多少次 (可重叠)
解题方法
kmp的基本用法 理解清楚失配函数的定义即可
参考代码 - 有疑问的地方在下方留言 看到会尽快回复的
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e4 + 10;int next[maxn];char w[maxn], t[maxn*100];void get_next() {int lenw = strlen(w);next[0] = next[1] = 0;for( int i=1; i<lenw; i++ ) {int f = next[i];while(f && w[f] != w[i]) f = next[f];if(w[f] == w[i]) next[i+1] = f + 1;else next[i+1] = 0;}}int main() {freopen("out", "r", stdin);int tcase;scanf("%d", &tcase);while(tcase--) {scanf("%s%s", w, t);get_next();int lenw = strlen(w), lent = strlen(t);int ans = 0, f = 0;for( int i=0; i<lent; i++ ) {while(f && w[f] != t[i]) f = next[f];if(w[f] == t[i]) f++;if(f == lenw) {f = next[f];ans++;}}printf("%d\n", ans);}return 0;}
0 0
- POJ 3461 Oulipo(简单KMP)
- POJ 3461 Oulipo (简单kmp)
- POJ 3461 Oulipo(简单KMP)
- poj 3461 Oulipo(简单的kmp入门)
- poj 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo---kmp
- POJ 3461 Oulipo KMP
- poj 3461 Oulipo (KMP)
- POJ 3461 Oulipo ( KMP )
- POJ 3461 Oulipo KMP
- POJ 3461 Oulipo / KMP
- Oulipo - POJ 3461 KMP
- 【KMP】 POJ 3461 Oulipo
- KMP---POJ 3461Oulipo
- POJ 3461 Oulipo (KMP)
- poj 3461 Oulipo kmp
- 【KMP】POJ-3461 Oulipo
- 5、构造器、类变量和单例
- c++运算符重载
- 116.Populating Next Right Pointers in Each Node
- Jquery面试题整合
- 跟Android说Hello World
- POJ 3461 Oulipo (简单kmp)
- Coredata的理解
- 黑马程序员--OC-多态与继承
- Masonry
- 日拱一卒(十三)
- [python3.x] 利用chardet检测网页编码
- 黑马程序员————java基础----数组
- swing JTable学习(五)—中给table中的cell加tips 以及用AbstractTableModel创建表格
- C++前置声明