Oulipo

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

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
 

kmp   ....经典题

思路清晰,就不多说啦!...

就是求目标串在主串中出现几次,即匹配几次,,.

代码:

 /*@coder 龚细军*/
#include<iostream>
#include<string>
#include<vector>
using namespace std; int main()
{
int t,i,j;
string pw,ps;
cin>>t;
while(t--)
{
i=,j=-;
cin>>pw>>ps; /*pw作为目标串,ps作为主串*/
int lenpw=pw.length();
int lenps=ps.length();
vector<int>next(lenpw+,);
next[i]=-;
while(i<lenpw)
{
if(j==-||pw[i]==pw[j])
{
++i;
++j;
if(pw[i]!=pw[j])
next[i]=j;
else
next[i]=next[j];
}
else
j=next[j];
}
i=-,j=-;
int ans=;
while(i<lenps)
{
if(j==-||pw[j]==ps[i])
{
++i;
++j;
}
else
j=next[j];
if(j==lenpw)
ans++;
}
printf("%d\n",ans);
}
return ;
}

HDUOJ -----1686的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. FZU 1686 神龙的难题 (重复覆盖)

    Problem 1686 神龙的难题 Accept: 397    Submit: 1258Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  3. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  4. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  5. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

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

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

  7. FZU 1686 神龙的难题 (DLX)

    神龙的难题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  8. PQJ 1686(栈栈栈)

    PQJ  1686(栈栈栈) 用栈解决问题 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  9. FZU 1686 神龙的难题(DLX反复覆盖)

    FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...

随机推荐

  1. 《JavaScript启示录》

    <JavaScript启示录> 基本信息 作者: (美)Cody Lindley 译者: 徐涛 出版社:人民邮电出版社 ISBN:9787115334947 上架时间:2014-2-21 ...

  2. 信号处理篇alarm ferror kill mkfifo pause pclose perror pipe popen sigaction sigaddset sigdelset sigemptyset signal sleep strerror

    alarm(设置信号传送闹钟) 相关函数 signal,sleep 表头文件 #include<unistd.h> 定义函数 unsigned int alarm(unsigned int ...

  3. scala编程第17章学习笔记(3)

    可变(mutable)集合与不可变(immutable)集合 为了更易于完成不可变集合到可变集合的转换,或者反向转换,Scala提供了一些语法糖.纵使不可变集和映射并不支持真正的+=方法,Scala还 ...

  4. RabbitMQ Zabbix 监控

    RabbitMQ Zabbix 监控 参考: https://github.com/jasonmcintosh/rabbitmq-zabbix copy api.py list_rabbit_node ...

  5. 附 Java对象内存布局

    注意:本篇博客,主要参考自<深入理解Java虚拟机(第二版)> 1.对象在内存中存储的布局分为三块 对象头 存储对象自身的运行时数据:Mark Word(在32bit和64bit虚拟机上长 ...

  6. Linux C Socket编程发送结构体、文件详解及实例

    利用Socket发送文件.结构体.数字等,是在Socket编程中经常需要用到的.由于Socket只能发送字符串,所以可以使用发送字符串的方式发送文件.结构体.数字等等. 本文:http://www.c ...

  7. 在C#中使用属性控制 XML 序列化来解析XML

    今天需要解析一个XML,这个XML和一般情况用.NET的序列化出来的格式不太一样. 我就又补习了一下. 分享一下学习成果吧. 示例代码下载: http://download.csdn.net/deta ...

  8. C#汉字转拼音,可识别多音字,带声调,提供正向、逆向、双向分词算法的小程序

    用C#写了个汉字转拼音的小工具,和网上大部分工具不同,这个通过分词算法,解决了多音字的问题,并且提供声调,可开可关. 如题,用"银行 行不行 行家说了算"举例,如果转拼音却不能识别 ...

  9. .NET/Mysql-petatoco连接mysql数据库

    安装mysql数据库 用nugget添加.net连接mysql数据库的组件

  10. 关于json与protobuf的材料

    1. https://solicomo.com/network-dev/protobuf-proto3-vs-proto2.html 2.