POJ 3461 Oulipo KMP
题意:统计其中一个子串的出现次数
题解:即KMP算法中j==m的次数
//作者:1085422276
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
//#include<bits/stdc++.h>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
const int inf = ;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
ll exgcd(ll a,ll b,ll &x,ll &y)
{
ll temp,p;
if(b==)
{
x=;
y=;
return a;
}
p=exgcd(b,a%b,x,y);
temp=x;
x=y;
y=temp-(a/b)*y;
return p;
}
//*******************************
int p[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
string a,b;
cin>>b>>a;
a=" "+a;
b=" "+b;
int m=b.length();
int n=a.length();
n--,m--;
memset(p,,sizeof(p));
int j=;
for(int i=;i<=m;i++)
{
while(j>&&b[j+]!=b[i])j=p[j];
if(b[j+]==b[i])j++;
p[i]=j;
}
int ans=;
j=;
for(int i=;i<=n;i++)
{
while(j>&&b[j+]!=a[i])j=p[j];
if(b[j+]==a[i])j++;
if(j==m){
ans++;
}
}
cout<<ans<<endl;
}
return ;
}
代码
POJ 3461 Oulipo KMP的更多相关文章
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
		题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ... 
- [POJ] 3461 Oulipo [KMP算法]
		Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23667 Accepted: 9492 Descripti ... 
- POJ 3461 Oulipo KMP算法题解
		本题就是给出非常多对字符串,然后问一个字符串在另外一个字符串出现的次数. 就是所谓的Strstr函数啦. Leetcode有这道差点儿一模一样的题目. 使用KMP算法加速.算法高手必会的算法了. 另外 ... 
- POJ 3461 Oulipo KMP算法(模板)
		题意: 给两组字符串a和b,求a在b中出现的次数 关于KMP: 马拉车算法是处理回文串,而KMP是处理前后缀的相同字符串的最长长度. a | a | b | a | a | f | a | a 数组 ... 
- POJ 3461 Oulipo(KMP,模式串在主串中出现次数 可重叠)
		题意:给你两个字符串p和s,求出p在s中出现的次数. 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 我先想直接把p接到s前面,之后求Next数组对st ... 
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
		HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ... 
- POJ 3461 Oulipo(乌力波)
		POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ... 
- POJ 3461	Oulipo[附KMP算法详细流程讲解]
		E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ... 
- POJ 3461 Oulipo 【KMP统计子串数】
		传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ... 
随机推荐
- Linux命令sed
			如果一个文本文件数据比较多,大概有40万条数据,我想取出第500-1000条数据,保存到另一个文件,用linux命令该如何操作? sed -n '500,1000p' 41w.txt > new ... 
- 微信JS-SDK
			<div class="lbox_close wxapi_form"> <h3 id="menu-basic">基础接口</h3& ... 
- linux远程连接客户端总结
			序:刚从阿里ECS买了一个ubuntu14.04_64_20G,但是没有提供页面登陆工具,因此从网上找了几个远程连接工具,特写在这里算是总结. 1 secureCRT SecureCRT是一款支持SS ... 
- 字符串模拟赛T1
			// source code from laekov for c0x17 #define PRID "bxjl" #include <cstdio> #include ... 
- thinkphp中模块和操作映射
			模板和操作映射功能是3.1.2版本支持的对模块和操作设置的映射机制,由于可以通过改变配置动态改变(实际真正改变,并非别名)URL访问地址,加强了应用的安全性,而且,映射机制具有URL不区分大小写访问的 ... 
- Lua中的捕获
			Lua中的捕获 捕获 捕获是这样一种机制:可以使用模式串的一部分匹配目标串的一部分.将你想捕获的模式用圆括号括起来,就指定了一个捕获.在string.find使用捕获的时候,函数会返回捕获的值作为 ... 
- bootstrap之双日历时间段选择控件示例—daterangepicker(汉化版)
			效果图: 参考代码: <link href="/public/static/common/css/daterangepicker.min.css?ver=0.6" rel=& ... 
- 成为Android高手必须掌握的28大项内容和10个建议
			(一)成为Android高手必须掌握的8项基本要求 [1] Android操作系统概述1. Android系统架构. 2. Android利用设计理念. 3. ... 
- Activity切换后,如i何保存上一个Activit的状态
			在Activity切换中一般有三种方式保存上一个Activity的状态数据.一.全局变量 public static int type = 0;二.SharedPreference 保 ... 
- spring boot实战(第十三篇)自动配置原理分析
			前言 spring Boot中引入了自动配置,让开发者利用起来更加的简便.快捷,本篇讲利用RabbitMQ的自动配置为例讲分析下Spring Boot中的自动配置原理. 在上一篇末尾讲述了Spring ... 
