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 ...
随机推荐
- 解决The requested resource is not available的办法
1.问题描述: eclipse中使用tomcat来运行HelloWorld时出现The requested resource is not available. 在报错中有一行Setting prop ...
- HTTP 各种特性应用(三)
一. 数据协商 分类: 客户端请求: Accept: Accept:表明 我想要什么样的数据 Accept-Encoding:数据是什么样的编码方式 进行传输.主要限制 服务端怎样进行数据的压缩. A ...
- Android中Service的一个Demo例子
Android中Service的一个Demo例子 Service组件是Android系统重要的一部分,网上看了代码,很简单,但要想熟练使用还是需要Coding. 本文,主要贴代码,不对Servic ...
- [Python] Create a Log for your Python application
Print statements will get you a long way in monitoring the behavior of your application, but logging ...
- 如何覆盖GCE的DHCP MTU选项
如何覆盖GCE的DHCP MTU选项 在GCE上托管的Linux IPSec隧道不能打开谷歌,这与MTU有关.谷歌管理员认为"改变这个值是一件困难的事情"https://cl ...
- Android圆形图片不求人,自定义View实现(BitmapShader使用)
在很多APP当中,圆形的图片是必不可少的元素,美观大方.本文将带领读者去实现一个圆形图片自定View,力求只用一个Java类来完成这件事情. 一.先上效果图 二.实现思路 在定义View 的onMea ...
- #学习笔记#——JavaScript 数组部分编程(五)
11.为数组 arr 中的每个元素求二次方.不要直接修改数组 arr,结果返回新的数组 function square(arr) { var resultArr=new Array(); for(va ...
- jquery实现瀑布流效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jupyter sparkmagic on hdp
1.安装jupyter 2.安装sparkmagic 3.设置超时 "livy_server_heartbeat_timeout_seconds": 0, 4.设置集群模式 &qu ...
- MyBatis学习总结(16)——Mybatis使用的几个建议
1.Mapper层参数为Map,由Service层负责重载. Mapper由于机制的问题,不能重载,参数一般设置成Map,但这样会使参数变得模糊,如果想要使代码变得清晰,可以通过service层来实现 ...