ppj3461 Oulipo

2023-11-07 21:09
文章标签 oulipo ppj3461

本文主要是介绍ppj3461 Oulipo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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.

kmp模板题。

#include<cstdio>
#include<cstring>
char a[10010],b[1000010];
int next[10010];
int main()
{int i,j,k,m,n,x,y,z,T,ans;scanf("%d",&T);while (T--){ans=0;scanf("%s%s",a+1,b+1);m=strlen(a+1);n=strlen(b+1);for (i=2,j=0;i<=m;i++){while (j>0&&a[i]!=a[j+1]) j=next[j];if (a[i]==a[j+1]) j++;next[i]=j;}for (i=1,j=0;i<=n;i++){while (j>0&&(j==m||b[i]!=a[j+1])) j=next[j];if (b[i]==a[j+1]) j++;if (j==m) ans++;}printf("%d\n",ans);}
}

这篇关于ppj3461 Oulipo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/366289

相关文章

poj 3461 Oulipo KMP算法

【题意】 给定n对字符串,求每组的前一个字符串在后一个字符串之中出现了几次 【输入】 第一行一个n 接下来n组数据 一组数据两行,分别是一个字符串 【输出】 对于每组数据,输出前一个字符串在后一个字符串之中出现了几次 escription The French author Georges Perec (1936–1982) once wrote a book, La dis

hdu——1686——Oulipo

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

HDU - 1686 Oulipo (KMP)

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 P

【题解】「POJ3461」Oulipo(字符串Hash)

题面 【题目描述】 给定两个串S1,S2,只有大写字母,求S1在S2中出现了几次。 【输入】 输入T组数据,每组数据两个串S1,S2. strlen(S1)<=10^4 strlen(S2)<=10^6, 【输出】 对于每组数据,输出答案。 【样例输入】 3BAPCBAPCAZAAZAZAZAVERDIAVERDXIVYERDIAN 【样例输出】 130 算法分析

poj 3461 Oulipo

http://poj.org/problem?id=3461(kmp入门)#include<stdio.h>#include<string.h>char p[1000000],s[1000000];int next[1000000];int n;void get_next(char *p){next[0]=-1;int i=-1,j=0;int len=strlen(p);w

信息学奥赛一本通 1455:【例题1】Oulipo

题目 1455:【例题1】Oulipo 分析 数据范围比较大,直接枚举会爆掉,需要字符串哈希,哈希值相同则两个字符串相同。 哈希就不说了,这里简单描述过程: 设定P,一般为131或13331设定模mod,一般取或,实际上用unsigned int或unsigned long long就可以,会自然溢出。设xp数组,预处理。设h数组,表示哈希值,,但字符串下标从1开始的哈希值为 这里

hdu 1686 Oulipo(简单KMP)只不过比赛的时候用了string.一直超时,改成char就一遍AC,纠结。。。

1、http://acm.hdu.edu.cn/showproblem.php?pid=1686 2、题目大意: 这道题目太纠结了,就是一道直接用KMP模板的题目,比赛的时候居然第一次想成做for循环次的KMP,超时了,后来知道只能用一次KMP了,结果用的string 一直超时,后来改成char居然一遍AC,还得好好熟悉算法 题目是给出两个字符串a,b,求a在b中出现多少次 3、题目:

HDU 1686:Oulipo ← KMP算法

【题目来源】http://acm.hdu.edu.cn/showproblem.php?pid=1686http://poj.org/problem?id=3461【题目描述】 The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a