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 数组 ...
随机推荐
- 【剑指offer】面试题44:扑克牌的顺子
题目: LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定 ...
- 轻量级开源嵌入式关系数据库sqlite基本使用及接口初识
preface,先闲来扯下蛋: 嵌入式数据库,NoSQL的是BerkeleyDB和InnoDB,leveDb.TC(个人较不熟悉),关系型嵌入式是SQLite; 服务器性质的NoSQL服务器,如Red ...
- js iframe 跳转
iframe 页面内操作: //iframe指向指定页面 parent.document.getElementById("hot").src = $("#hidPageU ...
- (转)iOS7界面设计规范(6) - UI基础 - 模态情境
继续规范.现在听着Clapton的Wonderful Tonight,想想看,整个高二暑假都在为这首歌着迷,经常夜里一边做英语暑期作业一边循环这首歌,心里特别静的赶脚.13年过去了,再听起来,就像隔着 ...
- Filter过滤器实现登录检查
主要利用filter过滤掉未经登录而直接跳转到非登录访问页面.代码而言的话并不难,只是有几点问题需要注意一下. 1.使用filter需要配置web.xml,如果是/*那么在拦截后的页面会连带jsp页面 ...
- 页面显示磁盘空间使用情况-Agedu
下载:http://www.chiark.greenend.org.uk/~sgtatham/agedu/ [root@localhost ~]# tar zxvf agedu-r9723.tar.g ...
- Linux系统相关
1. 图形界面启动的是哪个运行级别? 而我们平时用的命令行模式又是哪个运行级别? 除了图形和命令行模式两个常用级别外,其他运行级别代表什么涵义?如何更改系统的运行级别?图形界面启动的是5级别,命令行模 ...
- python - 消息队列
消息队列分类 1.先进先出 2.后进先出 3.优先级队列 4.双向队列 1.先进先出 import queue q = queue.Queue(2) #队列最大长度 q.put(11) q.put(2 ...
- 《第一行代码》学习笔记5-活动Activity(3)
1.Menu:让菜单得到展示的同时,不占用任何屏幕的空间. public boolean onCreateOptionsMenu(Menu menu){ getMenuInflater().infla ...
- oracle 全文检索
一.使用 sys 用户登录oracle (1)运行—cmd—sqlplus — sys/密码 @连接字符 as sysdba 二.授权 1.grant ctxapp to 全文检索使用用户: 2.gr ...