POJ--3461
原题链接:http://poj.org/problem?id=3461
分析:求一个串在另一个串中出现的次数,显然用KMP可以解决。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn1 10005
#define maxn2 1000005
using namespace std;
char s[maxn1],t[maxn2];
int next[maxn1],sum,len1,len2;
void get_next()
{
int i,j;len1=strlen(s);
next[]=-;
i=;j=-;
while(i<len1){
if(j==-||s[i]==s[j]){
i++;j++;
next[i]=j;
}
else j=next[j];
}
}
void kmp()
{
sum=;
get_next();
int i=-,j=-;len2=strlen(t);
while(i<len2){
if(j==-||t[i]==s[j])
{
i++;j++;
}
else j=next[j];
if(j==len1){
sum++;
j=next[j];
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s%*c%s",s,t);
kmp();
printf("%d\n",sum);
}
return ;
}
POJ--3461的更多相关文章
- POJ 3461 Oulipo
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- 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[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo(模式串在主串中出现的次数)
题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即 ...
- (KMP)Oulipo -- poj --3461
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ - 3461 (kmp)
题目链接:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...
- poj 3461 字符串单串匹配--KMP或者字符串HASH
http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include ...
随机推荐
- Ubuntu系统下在PyCharm里用virtualenv集成TensorFlow
我的系统环境 Ubuntu 18.04 Python3.6 PyCharm 2018.3.2 community(免费版) Java 1.8 安装前准备 由于众所周知的原因,安装中需要下载大量包,尽量 ...
- Python数据挖掘——数据概述
Python数据挖掘——数据概述 数据集由数据对象组成: 数据的基本统计描述 中心趋势度量 均值 中位数 众数 中列数 数据集的最大值和最小值的平均 度量数据分布 极差 最大值与最小值的差 四分位数 ...
- AngularJS学习之数据绑定
既然AngularJS是以数据作为驱动的MVC框架,在上一篇文章中,也介绍了AngularJS如何实现MVC模式的,所有模型里面的数据,都必须经过控制器,才能展示到视图中. 什么是数据绑定 首先来回忆 ...
- Requests库入门——应用实例-网络图片的爬取与保存(好看的小姐姐≧▽≦)
在B站学习这一节的时候,弹幕最为激烈,不管大家是出于什么目的都想体验一下网络爬虫爬取图片的魅力,毕竟之前的实例实话说都是一些没有太大作用的信息. 好了,直接上代码: import requests i ...
- python 二维矩阵及转byte知识点
1.注意python中的数组和list形式混合: 数组在numpy里面: 2.二维数组这样定义可以修改固定位置的值: rawDataArray_temp = [([0]*nIRImageWidth)f ...
- Struts2:<s:action>的使用
<s:action name=”actionName” namespace=”/” executeResult=”true”> <s:action>可以在jsp中直接调用act ...
- 数学口袋精灵感受与BUG
232朱杰 http://www.cnblogs.com/alfredzhu https://github.com/alfredzhu/ 组长,团队 230蔡京航 http://www.cnblogs ...
- 初探Android动画之门
原文地址:http://www.cnblogs.com/kross/p/3376451.html 最近自学了下动画的相关知识,总结为今天的文章,希望对大家有帮助. Android中的动画大致分为三种: ...
- java 基础 --集合--013
1, contains()方法底层依赖的是equals()方法,而定义的类中没有equal()方法,所以它会使用父类Object中的equals()方法,而Object的equals()方法比较的是地 ...
- 这套C#编码规范写不错
自己总结的C#编码规范--1.命名约定篇:http://www.cnblogs.com/luzhihua55/p/CodingConventions1.html 自己总结的C#编码规范--2.命名选择 ...