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 ...
随机推荐
- springboot 统一管理异常信息
新建ResponseEntityExceptionHandler的继承类:(依然,需要入口类扫描) /** * @author sky * @version 1.0 */ @ControllerAdv ...
- 比较两个文件是否相同(C/C++语言)
#include <stdio.h> #include <string.h> ; // Calculate the file size void Get_file_size(c ...
- POJ 1986 裸的LCA
思路:搞了一发链剖 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- POJ 3181完全背包(+高精)
思路: f[i]表示还剩i空间的方案数 套个高精 (网上有人把它拆成了两个long long) 其实这道题的高精并不难写-.. //By SiriusRen #include <cstdio&g ...
- Linux下配置Squid基础教程
Linux下配置Squid基础教程 本视频高清下载地址:http://down.51cto.com/data/437529 本文出自 "李晨光原创技术博客" 博客,请务必保留此出处 ...
- JavaScript Debug调试技巧
收藏于:https://blog.fundebug.com/2017/12/04/javascript-debugging-for-beginners/
- try{futureGirl}catch(Exception){"Kill All Trouble"}——echarts样式
首先先给未来女,解释一下题目吧.这是段代码,我再try{}括号里写了你,意思我会保护你.后面的catch(Exception)是捕捉你的所有麻烦,交给我解决. 今天收工较早,拖着疲惫是身躯回到宿舍,简 ...
- 【Uva 1627】Team them up!
[Link]: [Description] 给你n个人; 有一些人之间有认识关系 a认识b,b不一定认识a 让你把这n个人分成两组 使得这两组中的每一组: 组内的人与人之间都相互认识. 并且,使得两组 ...
- storm单词计数 本地运行
import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.HashM ...
- KendoUi中KendoDropDownList控件的使用——三级级联模块的实现
1. 应用需求 在权限系统开发中除了以上数据表关系的设计之外.比較麻烦的地方是级联模块在页面的展示,因为设计中最多是控制到三级,因此三级级联模块的展示.编辑等页面操作是须要解决的问题,这里採用Kend ...