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 ...
随机推荐
- 在performancepoint里面建立数据源的时候,总是发生以下的报警
就是我在performancepoint里面建立数据源的时候,总是发生以下的报警. 在管理中心主页的“应用程序管理”部分,单击“管理服务应用程序”,然后单击“PerformancePoint Se ...
- amaze ui各个模块简单说明
amaze ui各个模块简单说明 导航添加依据 http://amazeui.org/css/ 下面内容属学习笔记,如有理解偏差和错误请留言相告,感谢!* =(官网这块写的很详细) 一.基本样式 1 ...
- Springboot优化
https://www.cnblogs.com/chen110xi/p/6198481.html
- [论文笔记] CUDA Cuts: Fast Graph Cuts on the GPU
Paper:V. Vineet, P. J. Narayanan. CUDA cuts: Fast graph cuts on the GPU. In Proc. CVPR Workshop, 200 ...
- Json应用案例
Json应用案例之FastJson 这几天在网上找关于Json的一些案例,无意当中找到了一个我个人感觉比较好的就是阿里巴巴工程师写的FastJson. package com.jerehedu.f ...
- POJ 4047 Garden
Garden Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 404 ...
- 海康威视抓拍一体机--- C#源码
https://pan.baidu.com/s/1kV4AjRp 需要的联系qq:694666781
- netstat -p 显示 -
http://4735839.blog.51cto.com/4725839/1418945 https://yq.aliyun.com/articles/63060
- cocos2dx——lua自己主动和手动绑定
[自己主动绑定] 參考:http://my.oschina.net/skyhacker2/blog/298397 主要是通过引擎自带的tools/tolua,主要过程例如以下: 1.编写好要导出的c+ ...
- D. Dreamoon and Sets(Codeforces Round #272)
D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...