Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 37958   Accepted: 15282

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

 
 
思路:
  不说了,说多了都是笑>.<;
 
 
来,上代码:

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int ls,lt,T,next[]; char s[],t[]; inline void GetNext()
{
//memset(next,0,sizeof(next));
int k=-,j=;
next[j]=k;
while(j<lt)
{
if(k==-||t[j]==t[k])
{
k++,j++;
next[j]=k;
}
else k=next[k];
}
} inline int Kmp()
{
GetNext();
int i=,j=,return_=;
while(i<ls)
{
if(j==-||s[i]==t[j]) i++,j++;
else j=next[j];
if(j==lt)
{
j=next[j];
return_++;
}
}
return return_;
} int main()
{
scanf("%d",&T);
for(int i=;i<=T;i++)
{
cin>>t;
cin>>s;
ls=strlen(s);
lt=strlen(t);
cout<<Kmp()<<endl;
}
return ;
}

AC日记——Oulipo poj 3461的更多相关文章

  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. (KMP)Oulipo -- poj --3461

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 ...

  3. AC日记——Tree poj 3237

    Tree Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9233   Accepted: 2431 Description ...

  4. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  5. Match:Oulipo(POJ 3461)

     Oulipo 题目大意:给你一个字符串,要你找到字符串包含指定子串的个数 只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧 #include < ...

  6. AC日记——Crane poj 2991

    POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...

  7. AC日记——pigs poj 1149

    POJ - 1149 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include <iostream> # ...

  8. Oulipo POJ - 3461(kmp,求重叠匹配个数)

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

  9. AC日记——Dining poj 3281

    [POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...

随机推荐

  1. python字符编码小结

    首先简要说一下各种字符编码: 1. ASCII 计算机只认识0101,但如何让计算机认识人类语言?将每个字母和符号给予固定的编号,然后将这个编号转换成二进制,计算机就可以正确识别这些字母与符号,同时计 ...

  2. MySQL之索引(二)

    高性能的索引策略 正确地创建和使用索引是实现高性能查询的基础.在MySQL之索引(一)这一章中我们介绍了各种类型的索引及其对应的优缺点.现在我们一起来看看如何真正地发挥这些索引的优势. 独立的列 我们 ...

  3. Oracle 学习笔记(Windows 环境下安装 + PL/SQL)

    Oracle 安装.PL/SQL 配置使用  前言:因更换机械硬盘为 SSD 固态硬盘装了新 Windows 7 系统,需要重新搭建开发环境,把 Oracle 安装过程和 PL/SQL 配置使用做下笔 ...

  4. 《HTTP协议详解》读书笔记---请求篇之响应状态码

    在接收和解释请求消息后,服务器返回一个http响应消息.它也分为3个部分:状态行.消息报头.响应正文,格式如下: HTTP-VersionStatus-CodeReason-PhraseCRLF(CR ...

  5. 解决This application failed to start because it could not find or load the Qt platform plugin "windows

    解决方案:所在环境python根目录下qt.conf,重新设置path即可,此类问题通常在目录转移之后出现.

  6. [oldboy-django][2深入django]后台生成form标签并设置标签的属性

    # Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及submit标签还是要在前端写的, 但是Form标签内的Input标签可以在后台实现:只需要按以下步骤 - vi ...

  7. Android数据储存之File

    openFileOutStream 和 openFileInStream FileInputStream fileInputStream = openFileInput(name);  打开应用下文件 ...

  8. web项目中各种路径的获取(复制,为以后好找资源)

    web项目中各种路径的获取 1.可以在servlet的init方法里 String path = getServletContext().getRealPath("/"); 这将获 ...

  9. php 不重新编译增加openssl扩展

    安装openssl和开发包 yum install openssl openssl-devel 跳转到PHP源码下的openssl cd /usr/local/src/php-5.5.27/ext/o ...

  10. BZOJ4650 [NOI2016]优秀的拆分 【后缀数组】

    题目 如果一个字符串可以被拆分为 AABBAABB 的形式,其中 AA 和 BB 是任意非空字符串,则我们称该字符串的这种拆 分是优秀的.例如,对于字符串 aabaabaa,如果令 A=aabA=aa ...