Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16166    Accepted Submission(s): 6444

Problem 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

华东区大学生程序设计邀请赛_热身赛

Recommend

lcy

题解:

     ①KMP算法,统计匹配个数。

#include<stdio.h>
#include<cstring>
#define go(i,a,b) for(int i=a;i<=b;i++)
const int N=1000003;
int C,n,m,f[N],j,ans;char P[N],T[N];
int main()
{
scanf("%d",&C);
while(ans=0,C--&&scanf("%s%s",P,T))
{
m=strlen(P);
n=strlen(T);
f[0]=f[1]=0; go(i,1,m-1){j=f[i];while(j&&P[j]!=P[i])j=f[j];f[i+1]=P[i]==P[j]?j+1:0;}j=0;
go(i,0,n-1){while(j&&P[j]!=T[i])j=f[j];ans+=(j+=P[j]==T[i])==m;}
printf("%d\n",ans);
}
return 0;
}//Paul_Guderian

我曾经追寻的一切,现在都没有找到,
你知道我一直要的,不是这个角落…… ————汪峰《彼岸》

【HDU 1686 Oulipo】的更多相关文章

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

  2. HDU - 1686 Oulipo KMP匹配运用

    id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - ...

  3. HDU 1686 Oulipo【kmp求子串出现的次数】

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  4. hdu 1686 Oulipo 【KMP】(计算模式串匹配的次数——与已匹配的字串可以有交集)

    题目链接:https://vjudge.net/contest/220679#problem/B 题目大意: 输入一个T,表示有T组测试数据: 每组测试数据包括一个字符串W,T,T长度大于W小于100 ...

  5. 洛谷 P3375 【模板】KMP字符串匹配 || HDU 1686 Oulipo || kmp

    HDU-1686 P3375 kmp介绍: http://www.matrix67.com/blog/archives/115 http://www.cnblogs.com/SYCstudio/p/7 ...

  6. hdu 1686 Oulipo KMP匹配次数统计

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...

  7. HDU 1686 - Oulipo - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...

  8. hdu 1686 Oulipo kmp算法

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目: Problem Description The French author George ...

  9. HDU 1686 Oulipo(KMP变形求子串出现数目(可重))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给两个字符串A,B求出A中出现了几次B(计算重复部分). 解题思路:稍微对kmp()函 ...

随机推荐

  1. python_15_os

    import os #1. os.system('dir') #2 cmd_res=os.system('dir')#执行命令不保存结果 print("-------",cmd_r ...

  2. centos 7 虚拟机启用网卡

    1.vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 2.编辑默认网卡配置文件,将ONBOOT由no改为yes,编辑完成后,按ESC回至命令模板,输入&qu ...

  3. OO第四单元总结

    单元架构设计 本单元OO作业主要涉及两个过程,即先根据输入的elements数组建立UML存储模型,而后基于这个模型实现一系列查询判断功能.汲取上单元的经验,建模过程中模型数据容器的选择依据要求实现的 ...

  4. Python小脚本程序

    本文旨在搜集最简单最原子性的代码块,简单清晰容易阅读,然后由用户自己组合.Python代码排版请自行修改. 这里是索引目录: 1. 下载网站文件 2. 下载网站多个文件 1. 下载网站文件 impor ...

  5. SAP增强Enhancement

    第一代:基于源码增强(子过程subroutine) 第一代增强基于源代码,是SAP提供的一个空代码的子过程.在这个子过程中用户可以添加自己的代码,控制自己的需求.这类增强集中在一些文件名倒数第二个字符 ...

  6. phpstorm —— Xdebug 的配置和使用

    给phpstorm 配置Xdebug(Xdebug 是 PHP 的一个扩展, 用于帮助调试和开发.它包含一个与 ide 一起使用的单步调试器.它升级了 PHP 的 var_dump () 功能) 这篇 ...

  7. mysql四:数据操作

    一 介绍 MySQL数据操作: DML ======================================================== 在MySQL管理软件中,可以通过SQL语句中的 ...

  8. 大数据小项目之电视收视率企业项目08--》MapReduce编写之Wordcount

    编程规范 (1)用户编写的程序分成三个部分:Mapper,Reducer,Driver(提交运行mr程序的客户端) (2)Mapper的输入数据是KV对的形式(KV的类型可自定义) (3)Mapper ...

  9. python面向对象之反射和内置方法

    一.静态方法(staticmethod)和类方法(classmethod) 类方法:有个默认参数cls,并且可以直接用类名去调用,可以与类属性交互(也就是可以使用类属性) 静态方法:让类里的方法直接被 ...

  10. 精通SpringBoot:详解WebMvcConfigurer接口

    SpringBoot 确实为我们做了很多事情, 但有时候我们想要自己定义一些Handler,Interceptor,ViewResolver,MessageConverter,该怎么做呢.在Sprin ...