B - Oulipo
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.
InputThe 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.
OutputFor 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
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 1000001
typedef long long LL;
/*
KMP 查找子串出现的次数
*/
char s[MAXN],t[MAXN];
int Next[MAXN];
void pre_kmp(int m)
{
int j,k;
j = ;k = -;Next[] = -;
while(j<m)
if(k==-||t[k]==t[j])
Next[++j] = ++k;
else
k = Next[k];
}
int KMP(char s[],char t[],int n,int m)
{
int i,j,ans;
i = j = ans = ;
if(n==&&m==)
return (s[]==t[])?:;
pre_kmp(m);
for(i=;i<n;i++)
{
while(j>&&s[i]!=t[j])
j = Next[j];
if(s[i]==t[j])
j++;
if(j==m)
{
ans++;
j = Next[j];
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s%s",t,s);
printf("%d\n",KMP(s,t,strlen(s),strlen(t)));
}
}
B - Oulipo的更多相关文章
- C++之路进阶——poj3461(Oulipo)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35694 Accepted: 14424 Descript ...
- poj3461 Oulipo(KMP模板)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17795 Accepted: 7160 Descripti ...
- Match:Oulipo(POJ 3461)
Oulipo 题目大意:给你一个字符串,要你找到字符串包含指定子串的个数 只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧 #include < ...
- KMP算法 hdu4686 Oulipo
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- hdu----1686 Oulipo (ac自动机)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 字符串hash - POJ 3461 Oulipo
Oulipo Problem's Link ---------------------------------------------------------------------------- M ...
- POJ 3461 Oulipo
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- Oulipo (kmp)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26857 Accepted: 10709 Descript ...
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- A - Oulipo
A - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
随机推荐
- html5拨打电话及发短信
1.最常用WEB页面一键拨号的电话拨打功能 <a href="tel:15088888888">拨号</a> 2.最常用WEB页面一键发送短信功能: < ...
- 基于Linux的v4l2视频架构驱动编写(转载)
转自:http://www.linuxidc.com/Linux/2011-03/33022.htm 其实,我刚开始一直都不知道怎么写驱动,什么都不懂的,只知道我需要在做项目的过程中学习,所以,我就自 ...
- PCB Genesis 无需启动Xmanager图形窗口运行脚本 实现方法
从事PCB工程行业的都知道,启动Genesis需2个exe程序(Xmanager.exe与get.exe)需一起启动才可以打开我们熟悉的软件, 而Xmanager是图形窗口是给用户UI交互使用的,如果 ...
- Akka源码分析-深入ActorRef&ActorPath
上一节我们深入讨论了ActorRef等相关的概念及其关系,但ActorRef和ActorPath的关系还需要再加以分析说明.其实还是官网说的比较清楚. “A path in an actor syst ...
- [Luogu 1312] noip11 Mayan游戏
[Luogu 1312] noip11 Mayan游戏 Problem: Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个 7 行5 列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即 ...
- ACM_变形课(并查集)
变形课 Time Limit: 2000/1000ms (Java/Others) Problem Description: 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermio ...
- cmd bat 相对命令
"%~dp0",在BAT中,是不是“相对路径”的意思 (2013-08-21 12:19:32) 转载▼ 标签: 杂谈 分类: C# 0念 零 ,代表你的批处理本身. d p是FO ...
- 【sqli-labs】 less47 GET -Error based -String -Order By Clause(GET型基于错误的字符型Order By从句注入)
http://192.168.136.128/sqli-labs-master/Less-47/?sort=1 改变sort的值,结果仍然是order by 1的结果 http://192.168.1 ...
- HDU_1394_Minimum Inversion Number_线段树求逆序数
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- Python 之selenium+phantomJS斗鱼抓取案例
from selenium import webdriver from bs4 import BeautifulSoup import time if __name__ == '__main__': ...