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下划线部 ...
随机推荐
- ASP.NET MVC3 Razor视图引擎-基础语法
I:ASP.NET MVC3在Visual Studio 2010中的变化 在VS2010中新建一个MVC3项目可以看出与以往的MVC2发生了很明显的变化. 1.ASP.NET MVC3必要的运行环境 ...
- 198,House Robber
一.题目 You are a professional robber planning to rob houses along a street. Each house has a certain a ...
- JAVA GUI学习 - 窗体背景图片设置方法:重写paintComponent(Graphics g)方法
public class BackgroundImage extends JFrame { public BackgroundImage() { this.setTitle("窗体背景图片设 ...
- Save Princess(丑数)
Save Princess 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Yesterday, the princess was kidnapped by a de ...
- 安装帝国CMS遇到“修改php.ini,将:short_open_tag 设为 On”的解决方法+“建立目录不成功!请检查目录权限”问题
想用安装个帝国CMS来做个网站,于是下载了程序,上传到服务器上,但是在输入安装路径的时候却给出了如下图示: 您的PHP配置文件php.ini配置有问题,请按下面操作即可解决: 1.修改php.ini, ...
- 从零搭建LNMP环境
Linux就是环境所在的操作系统: Nginx则是一个「高性能的HTTP和反向代理服务器」,官网地址:http://nginx.org/: MySQL则是一个方便地对数据进行增删改查的数据库管理系统, ...
- Ubuntu14.04 Y460闪屏问题解决方案
我的笔记本是联想Y460,安装了Ubuntu之后发现屏幕闪烁移位,而且在使用IDE的时候出现无法输入中文等问题,其实是显卡驱动的问题,N卡官网给的驱动不好用,尝试使用大黄蜂 参考:https://wi ...
- JavaEE Tutorials (3) - 企业bean
3.1什么是企业bean383.1.1企业bean的好处393.1.2何时使用企业bean393.1.3企业bean类型393.2什么是会话bean393.2.1会话bean类型403.2.2何时使用 ...
- DHTML【11】--DOM
大家好,从今天开始,我们将进入DOM的学习. DOM?DOM是何东东呢?大家还记得我在前面提过的DOM树吗?就是我在前面讲HTML的时候画的那个图,那个其实就是一个简单的DOM树,浏览器在解析HTML ...
- Android新增API之AudioEffect中文API与应用实例
在Android2.3中增加了对音频混响的支持,这些API包含在android.media.audiofx包中. 一.概述 AudioEffect是android audio framework(an ...