传送门

Oulipo
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 32373   Accepted: 13093

Description

The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:

Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, puis surgissait l’inhumain, l’affolant. Il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : stir son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…

Perec would probably have scored high (or rather, low) in the following contest. People are asked to write a perhaps even meaningful text on some subject with as few occurrences of a given “word” as possible. Our task is to provide the jury with a program that counts these occurrences, in order to obtain a ranking of the competitors. These competitors often write very long texts with nonsense meaning; a sequence of 500,000 consecutive 'T's is not unusual. And they never use spaces.

So we want to quickly find out how often a word, i.e., a given string, occurs in a text. More formally: given the alphabet {'A''B''C', …, 'Z'} and two finite strings over that alphabet, a word W and a text T, count the number of occurrences of W in T. All the consecutive characters of W must exactly match consecutive characters of T. Occurrences may overlap.

Input

The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

  • One line with the word W, a string over {'A''B''C', …, 'Z'}, with 1 ≤ |W| ≤ 10,000 (here |W| denotes the length of the string W).
  • One line with the text T, a string over {'A''B''C', …, 'Z'}, with |W| ≤ |T| ≤ 1,000,000.

Output

For every test case in the input file, the output should contain a single number, on a single line: the number of occurrences of the word W in the text T.

Sample Input

3
BAPC
BAPC
AZA
AZAZAZA
VERDI
AVERDXIVYERDIAN

Sample Output

1
3
0

Source

 
 
15266997 njczy2010 3461 Accepted 1736K 125MS G++ 1147B 2016-03-14 17:00:52
 
题意:
裸的kmp
 
代码:
 #include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm> using namespace std; #define N 1000005
#define ll long long int TT;
char s[N];
char t[N];
int next[N];
int ans;
int l;
int lt; void get_next()
{
int i,j;
i = ;
j = -;
next[] = -;
while(i<l)
{
if(j == - || s[i] == s[j]){
i++;j++;next[i] = j;
}
else{
j = next[j];
}
}
} void kmp()
{
int i,j;
i = ;
j = ;
while(i < lt)
{
if(j == - || t[i] == s[j]){
if(j == l - ){
ans ++;
j = next[j];
}
else{
i++;j++;
}
}
else{
j = next[j];
}
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&TT);
while(TT--){
//while(scanf("%I64d%I64d",&n,&k)!=EOF){
ans = ;
scanf("%s",s);
l = strlen(s);
scanf("%s",t);
lt = strlen(t);
get_next();
kmp();
printf("%d\n",ans);
}
return ;
}

poj 3461 Oulipo,裸kmp的更多相关文章

  1. POJ 3461 Oulipo[附KMP算法详细流程讲解]

      E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  2. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  3. POJ 3461 Oulipo(KMP裸题)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  4. poj 3461 Oulipo(KMP模板题)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Descript ...

  5. POJ 3461 Oulipo(——KMP算法)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  6. poj 3461 - Oulipo 经典kmp算法问题

    2017-08-13 19:31:47 writer:pprp 对kmp算法有了大概的了解以后,虽然还不够深入,但是已经可以写出来代码,(可以说是背会了) 所以这道题就作为一个模板,为大家使用吧. 题 ...

  7. poj 3461 Oulipo(kmp统计子串出现次数)

    题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...

  8. poj 3461 Oulipo(KMP)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49378   Accepted: 19617 Descript ...

  9. 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 ...

随机推荐

  1. HtmlUnit爬取Ajax动态生成的网页以及自动调用页面javascript函数

    HtmlUnit官网的介绍: HtmlUnit是一款基于Java的没有图形界面的浏览器程序.它模仿HTML document并且提供API让开发人员像是在一个正常的浏览器上操作一样,获取网页内容,填充 ...

  2. 在vue组件库中不能使用v-for

    没事的,有点时候编辑器报错,但运行不一定出错, 在vue组件中注意template标签

  3. 栈的应用——Rails

    一.题目描述 某城市有一个火车站,有n节车厢从A方向驶入车站,按进站顺序编号为1~n,经中转站C驶向B.中转站C,这是一个可以停放任意多节车厢的车站,但由于末端封顶,驶入C的车厢必须以相反的顺序驶出C ...

  4. RMQ求区间最大最小值

    #include<iostream> #include<cmath> #include<cstdio> #define N 50005 using namespac ...

  5. grep, egrep, fgrep - 打印匹配给定模式的行

    总览 SYNOPSIS grep [options] PATTERN [FILE...] grep [options] [-e PATTERN | -f FILE] [FILE...] 描述 DESC ...

  6. Burpsuite1.7.03网站渗透神器最新破解版

    众所周知,Burp Suite是响当当的web应用程序渗透测试集成平台.从应用程序攻击表面的最初映射和分析, 到寻找和利用安全漏洞等过程,所有工具为支持整体测试程序而无缝地在一起工作. 平台中所有工具 ...

  7. linux环境nginx的安装与使用

    因为公司需要需要安装一系列环境,新手上路第一次配的时候什么也不懂在网上找了半天,觉得这篇不错,我在这里顺便记录一下.(原文:https://www.cnblogs.com/wyd168/p/66365 ...

  8. Java中的线程--并发库中的集合

    线程中的知识点基本都已经学完了,看看Java5并发库中提供的集合... 一.可堵塞队列 队列包含固定长度的队列和不固定长度的队列 ArrayBlockQueue中只有put()方法和take()方法才 ...

  9. linux中添加一个用户到指定用户组的两种方式,修改一个用户到指定用户组的一种方式

    添加一个用户到指定用户组: gpasswd –a 用户名 组名usermod –G 组名 用户名 //第一种:gpasswd –a 用户名 组名 [root@localhost ~]# id user ...

  10. GIMP图片头发的处理

    1/选中图片,添加Alpha Channel 2/点击Duplicate Layer,复制图层: 3/接着需要调整一下色差,选中Color下的Curves,调节曲线,使背景看起来更白一点 4/选中Co ...