POJ Oulipo (KMP)
题目大意 : 在一个字符串中找出目标单词的个数
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define INF 0x7fffffff
char t[1000010],w[10010];
int next[10010];
void getnext(int wlen){
int i,j;
next[0] = 0;
next[1] = 0;
for(i=1;i<wlen;i++){
j = next[i];
while(j && w[i] != w[j]) j = next[j];
if(w[i] == w[j]) next[i+1] = j+1 ;
else next[i+1] = 0 ;
}
}
int KMP(){
int i,j,tlen,wlen,cnt = 0;
tlen = strlen(t);
wlen = strlen(w);
j = 0;
getnext(wlen);
for(i=0;i<tlen;i++){
while(j && w[j] != t[i]) j = next[j];
if(w[j] == t[i]) j++;
if(j>=wlen)
cnt ++;
}
return cnt ;
}
int main(){
int i,j,n,cnt;
cin >> n;
for(i=1;i<=n;i++){
scanf("%s%s",w,t);
printf("%d\n",KMP());
}
return 0;
}
POJ Oulipo (KMP)的更多相关文章
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...
- poj3461 Oulipo —— KMP
题目链接:http://poj.org/problem?id=3461 代码如下: #include<cstdio>//poj 3461 kmp #include<cstring&g ...
- [POJ] 3461 Oulipo [KMP算法]
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23667 Accepted: 9492 Descripti ...
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- POJ 3461 Oulipo KMP
题意:统计其中一个子串的出现次数 题解:即KMP算法中j==m的次数 //作者:1085422276 #include <cstdio> #include <cmath> #i ...
- 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 数组 ...
随机推荐
- URAL 1658
题目大意:求出T个最小的满足各个位的和为S1,平方和为S2的数.按顺序输出.数的位数大于100或者不存在这样一个数时,输出:No solution. KB 64bit IO Format:%I ...
- bootstrap学习以及其插件
Bootstrap中文网地址,里面有bootstrap组件的下载与使用说明,现在使用bootstrap3: http://www.bootcss.com/ W3CSchool.CC里面有学习boots ...
- struts配置,略记
<!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener ...
- wex5添加视频播放
我使用的播放器是ckplayer http://www.ckplayer.com/ ckplayer存放路,项目路径下: 方法一: 在monitor.w里加一个div标签 <div id=&qu ...
- junit4测试 Spring MVC注解方式
本人使用的为junit4进行测试 spring-servlet.xml中使用的为注解扫描的方式 <?xml version="1.0" encoding="UTF- ...
- eclipse 集成maven插件
本文转载自:http://www.blogjava.net/fancydeepin/archive/2012/07/13/eclipse_maven3_plugin.html 环境准备: eclips ...
- MyEclipse 安装activiti designer
下载activiti designer 文件地址:http://activiti.org/designer/archived/ 注意:我的是myeclipse9.0,我下载的版本是:(当我下载高版本安 ...
- mysql 中的数据类型
unsigned 既为非负数,用此类型可以增加数据长度! 例如如果 tinyint最大是127,那 tinyint unsigned 最大 就可以到 127 * ...
- c语言构建动态数组
#include <stdio.h> #include <stdlib.h> int main(void) { int len; int * arr; printf(" ...
- asp.net从服务器(指定文件夹)下载任意格式的文件到本地
一.我需要从服务器下载ppt文件到本地 protected void Btn_DownPPT_Click(object sender, EventArgs e) { ...