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
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int b[];//之前用next[10005]CE,不明确,可能有函数吧。。。,好坑
char ch1[],ch2[];
void get_next(int len1)
{
int i=,j=-;
b[]=-;
while(i<len1)
{
if(j==-||ch1[i]==ch1[j])
{
i++;j++;
if(ch1[i]==ch1[j])
b[i]=b[j];
else
b[i]=j;
}
else
j=b[j];
}
}
int kmp(int len1,int len2)
{
int i=,j=,k=;
get_next(len1);
while(i<len2)
{
if(j==-||ch2[i]==ch1[j])
{i++;j++;}
else
{
j=b[j];
}
if(j==len1)
{
k++;
}
}
return k;
} int main()
{
int n;
cin>>n;
getchar();
while(n--)
{
cin>>ch1>>ch2;
int len1,len2;
len1=strlen(ch1);
len2=strlen(ch2);
get_next(len1);
cout<<kmp(len1,len2)<<endl;
}
return ;
}
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下划线部 ...
随机推荐
- C89, C99, C11: All the specifics that I know
before anything.. sizeof is an operand! sizeof is an operand! sizeof is an operand! 重要なことは三回にしませんね! ...
- PhotonServer 学习
版本:Photon-OnPremise-Server-SDK_v3-4-31-10808 输出文件夹:deploy/名称/bin PhotonServer.config 配置 <Applicat ...
- Android:View颤抖的动画效果代码
public void propertyValuesHolderDown(final View view) { PropertyValuesHolder pvhX = PropertyValuesHo ...
- KVM设置DHCP、DNS、Gateway
添加网卡 sudo vi /etc/network/interfaces #添加下面的配置 >>>>>>>> auto tap0 iface tap0 ...
- HTML表格标记
- window.open打开新页面居中
var iHeight = 500;//新打开页面的高 var iWidth = 800;//新打开页面的宽 var iTop = (window.screen.height-30-iHeight)/ ...
- js--javascript中字符串常用操作总结、JS字符串操作大全
字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用操作做个整理,一者加深印象,二者方便今后温 ...
- GIAC全球互联网架构大会——互联网技术架构未来
GIAC全球互联网架构大会是高可用架构技术社区推出的面向架构师.技术负责人及高端技术从业人员的技术架构大会.中国拥有全球最大的互联网用户及移动互联网用户,如何使用合适的架构来搭建互联网系统,是每一个互 ...
- Java Swing 日期控件(转载)
http://www.cnblogs.com/lzy1991/p/5714935.html
- ggplot2 geom相关设置——添加线条
在作图过程中,有时我们可能需要通过添加一些线条,使得图形的可视化变得更好,比如一些趋势线等等. 下面我们来看下,一些线条的添加方式. geom_abline(mapping = NULL, data ...