POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数
思路:KMP模板题
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define LL long long
#define pii (pair<int, int>)
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; const int maxt = 1000000 + 100;
const int maxp = 10000 + 100;
//const int INF = 0x3f3f3f3f; char P[maxp], T[maxt];
int f[maxp]; void getFail() {
int m = strlen(P);
f[0] = 0; f[1] = 0;
for(int i = 1; i < m; i++) {
int j = f[i];
while(j && P[i]!=P[j]) j = f[j];
f[i+1] = P[i]==P[j] ? j+1 : 0;
}
} int find_p() {
int ans = 0;
int n = strlen(T), m = strlen(P);
getFail();
int j = 0;
for(int i = 0; i < n; i++) {
while(j && P[j]!=T[i]) j = f[j];
if(P[j] == T[i]) j++;
if(j == m) ans++, j=f[j];
}
return ans;
} int main() {
//freopen("input.txt", "r", stdin);
int t; cin >> t;
while(t--) {
scanf("%s%s", P, T);
int ans = find_p();
cout << ans << endl;
}
return 0;
}
POJ Oulipo(KMP模板题)的更多相关文章
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- HDU 1686 - Oulipo - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...
- poj3461 Oulipo (KMP模板题~) 前面哪些也是模板题 O.O
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...
- HDU 1711 - Number Sequence - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
- Number Sequence - HDU 1711(KMP模板题)
题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1 分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...
- hdu 1711 Number Sequence(KMP模板题)
我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...
- HDU 1711Number Sequence【KMP模板题】
<题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...
- (模板)poj3461(kmp模板题)
题目链接:https://vjudge.net/problem/POJ-3461 题意:给出主串和模式串,求出模式串在主串中出现的次数. 思路:kmp板子题. AC代码: #include<cs ...
随机推荐
- 4.graph.h
#pragma once #include <stdio.h> #include <graphics.h> #include <mmsystem.h> #pragm ...
- BZOJ 1055 DP
思路: f[i][j][k]表示i到j匹配了字母k if(m,n能匹配上k) f[i][j][k]|=f[i][l][m]&f[l+1][j][n] 一个大枚举 就OK了~ //By Siri ...
- IntelliJ IDEA springmvc demo
construction pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...
- Web 端 js 导出csv文件
http://www.qdfuns.com/notes/35821/2ab249182734d1f5c66da6b5cf395db9.html
- Redis学习手冊(事务)
一.概述: 和众多其他数据库一样,Redis作为NoSQL数据库也相同提供了事务机制. 在Redis中,MULTI/EXEC/DISCARD/WATCH这四个命令是我们实现事务的基石. 相 ...
- android启动模式对于体验的影响
说到Android的启动模式.懂Android的人肯定都懂. 通过设置启动模式我们不仅能够节省内存的使用.还能达到更好的体验,比方我们打开一个应用,点击home键回到主界面的时候程序是没有被kill掉 ...
- 转 SQL集合函数中利用case when then 技巧
SQL集合函数中利用case when then 技巧 我们都知道SQL中适用case when then来转化数据库中的信息 比如 select (case sex when 0 then '男' ...
- HDU 6153 A Secret
A Secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)Total ...
- PatentTips - Control register access virtualization performance improvement
BACKGROUND OF THE INVENTION A conventional virtual-machine monitor (VMM) typically runs on a compute ...
- 洛谷 P2108 学英语
P2108 学英语 题目描述 为了适应紧张的大学学习生活,小Z发愤图强开始复习巩固英语. 由于小Z对数学比较有好感,他首先复习了数词.小Z花了一整天的时间,终于把关于基数词的知识都搞懂了.于是小Z非常 ...