HDU1686——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.
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.
BAPC
BAPC
AZA
AZAZAZA
VERDI
AVERDXIVYERDIAN
3
0
KMP第二弹~
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
char a[1000007],b[10007];
int next[10007];
int c;
int m,n;
void getnext()
{
int i=0;
int j=-1;
next[0]=-1;
while(i<n)
{
if(j==-1||b[j]==b[i])
{
i++;
j++;
if(b[j]==b[i])
next[i]=next[j];
else
next[i]=j;
}
else
j=next[j];
}
} int kmp()
{
int i=0,j=0;
while(i<m&&j<n)
{
if(j==-1||a[i]==b[j])
{
i++;
j++;
}
else
j=next[j];
if(j==n)
{
j=next[j];
c++;
}
}
return c;
}
int main()
{
int test;
scanf("%d",&test);
getchar();
while(test--)
{
memset(next,0,sizeof(next));
c=0;
gets(b);
gets(a);
m=strlen(a);
n=strlen(b);
getnext();
printf("%d\n",kmp());
}
return 0;
}
HDU1686——Oulipo的更多相关文章
- hdu----1686 Oulipo (ac自动机)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU-1686 Oulipo
学习:重点理解这句话的意思: next[j]会告诉我们从哪里开始匹配 模板题. Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU1686:Oulipo
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- hdu1686 Oulipo KMP/AC自动机
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- hdu1686 Oulipo kmp
题目传送门 思路:kmp模板,稍微修改下 #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using name ...
- [hdu1686] Oulipo【KMP】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1686 保存KMP模版,代码里P是模版串,next[]就是为它建立的.T是文本串,就是一般比较长的.nex ...
- HDU1686 Oulipo 题解 KMP算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给你一个子串t和一个母串s,求s中有多少个子串t. 题目分析:KMP模板题. cal_ ...
- AC自动机基础知识讲解
AC自动机 转载自:小白 还可参考:飘过的小牛 1.KMP算法: a. 传统字符串的匹配和KMP: 对于字符串S = ”abcabcabdabba”,T = ”abcabd”,如果用T去匹配S下划线部 ...
随机推荐
- [WPF疑难]如何禁用窗口上的关闭按钮
原文 [WPF疑难]如何禁用窗口上的关闭按钮 [WPF疑难]如何禁用窗口上的关闭按钮 周银辉 哈哈,主要是调用Rem ...
- elk 搭建
elk 平台搭建: ELK平台搭建 系统环境 System: Centos release 6.7 (Final) ElasticSearch: 2.1.0 Logstash: 2.1.1 Kiban ...
- libpng causes error concerning pngconf.h
Bug Description Ubuntu Gutsy Gibbon 7.10 - libpng 1.2.15~beta5-2ubuntu0.1 (bug probably concerned wi ...
- 如何使用W5300实现ADSL连接(一)
在介绍W5300连接ADSL之前,先给大家简单介绍一下WIZnet W5300这款芯片. W5300是WIZnet公司的一款单芯片器件,采用0.18μmCMOS工艺,内部集成10/100M以太网控制器 ...
- jQuery报错:Uncaught ReferenceError: $ is not defined
在使用jQuery的时候,发现有如下报错: Uncaught ReferenceError: $ is not defined (anonymous function) 出现这个报错的原因: 1.j ...
- svn恢复到之前某个版本号
一直在找svn回滚的方法,这个还是非常有用的,屡试不爽阿 常常因为坑爹的需求,功能要切回到之前的某一个版本号.有两种方法能够实现: 方法1: 用svn merge 1) 先 svn up,保证更新到 ...
- Swift入门Hello World! Swift.
苹果公司推出新的开发语言Swift,随着关于趋势,外观和OC什么是不一样的地方. 前提条件:已安装Xcode6-Beta(这个过程是不表) 1.打开Xcode6-Beta,第二选择Create a n ...
- c语言 ,回调函数[个人理解]
回调函数:把需要调用的方法的指针pCallBackFuncX作为参数传递给一个函数UsrFunction,以便该UsrFunction函数在处理相似事件的时候可以灵活的使用不同的方法. 以在fla ...
- ADO.NET 总结
一.简单介绍ADO.NET System.Data:DataTable,DataSet,DataRow,DataColumn,DataRelation,Constraint System.Data.C ...
- Pascal Analyzer 4 代码分析使用简要说明
概述 不管在那个开发团队中每个人的编写风格往往是千差万别能力也有高低,如何让别人快速看懂自己的代码维护你的代码.尽量避免不必要的简单错误,为编写代码作一定的约束是必不可少的.如果你说我一个人不需要规范 ...