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下划线部 ...
随机推荐
- "No appenders found for logger" and "Please configure log4j properly"
Why do I see a warning about "No appenders found for logger" and "Please configure lo ...
- ORA-00845 Oracle 启不来修改 MEMORY_TARGET
1.内存减小导致Oracle启动不了 Last login: Sun Nov 4 15:09:06 2012 from 192.168.5.222 [oracle@h1 ~]$ sqlplus ...
- POJ 3518 Prime Gap(素数题)
[题意简述]:输入一个数,假设这个数是素数就输出0,假设不是素数就输出离它近期的两个素数的差值,叫做Prime Gap. [分析]:这题过得非常险.由于我是打的素数表. 由于最大的素数是1299709 ...
- ThinkPHP - 独立分组项目搭建
配置文件: <?php return array( //独立分组 'APP_GROUP_LIST' => 'Home,Admin', //分组列表 'APP_GROUP_MODE' =&g ...
- DZNEmptyDataSet框架简介
给大家推荐一个设置页面加载失败时显示加载失败等的框架. 下载地址:DZNEmptyDataSet https://github.com/dzenbot/DZNEmptyDataSet 上效果首先在你的 ...
- 怎样使用windows命令行,用notepad打开某文件夹下面的所有文件
http://zhidao.baidu.com/question/2138815012359999388.html __________________________________________ ...
- 【centos6 , 7】 网络原理、网络配置
第一部分:网络原理: 一.网络编址 (主要使用IP编址) 1.ip编址是一个双层编址方案,一个ip地址标识一个主机(或一个网卡接口) 2.现在应用最为广泛的是IPv4编址,已经开始逐渐向IPv6编址转 ...
- 【转】OpenCV中使用神经网络 CvANN_MLP
原文见:http://blog.csdn.net/xiaowei_cqu/article/details/9027617 OpenCV的ml模块实现了人工神经网络(Artificial Neural ...
- 使用webservice实现App与服务器端数据交互
What? webservice曾经认为是解决异构系统间整合的最佳解决方案,不依赖于第三方任何系统的支持(不需要部署RDBMS服务器),大家只需要按照官方的规范,即可完成相互之间的数据交互. Why? ...
- mongoose 数据库操作 - 分页
使用mongoose 加入分页方法,临时还没发现什么更好的方法,我使用的方法是,直接在源代码中加入 找到 node_modules/mongoose/lib/model.js打开这个文件.里面加入这段 ...