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下划线部 ...
 
随机推荐
- haoce修改mysql
			
修改时长余额 select * from sys_user_product up where up.user_id in(select u.id from sys_user u where login ...
 - U盘安装VMware ESXi 6.0
			
准备工作 在vmware官网注册,并获取ESXi 6.0 ISO Image: 下载UNetbootin: 容量1GB或以上的U盘,将其格式化. U盘制作 打开UNetbootin,如下图设置,文件路 ...
 - IAsyncResult 接口异步 和匿名委托
			
IAsyncResult 接口异步 DataSet ds = new DataSet(); Mydelegate del = new Mydelegate(LoadData); IAsyncResul ...
 - ThinkPHP批量添加数据和getField()示例
			
批量添加数据 // 批量添加数据 $User = M('users'); $dataList[] = array('name'=>'thinkphp','email'=>'thinkphp ...
 - intellij idea 12 搭建maven web项目
			
原来公司一直使用eclipse,突然使用这个intellij还真有点不习惯,等用了一段时间才发现的确好用,因为也是刚开始用,所以很多不理解的地方,搭建一个项目从头好好了解下intellij 最开始的m ...
 - push类型消息中间件-消息服务端(三)
			
1.连接管理 网络架构原来是使用是自己开发的网络框架Gecko,Gecko默认为每个网络连接分配64KB的内存,支持1000个网络连接,就需要大概64MB的内存.后来采用Netty重构了网络服务层. ...
 - Date 和 SimpleDateFormat 类表示时间
			
Date now=new Date(); // 使用format()方法将日期转换为指定格式的文本 SimpleDateFormat sdf1 = new SimpleDateFormat(" ...
 - WEB前端开发中的图片压缩
			
web前端开发中,图片的重要性不言而喻,而由于一些图片的大小加上现在国内的网速不给力等种种原因,我们非常有必要对网站使用的图片进行压缩,压缩图片必然会带来图片质量的损失,我们要尽可能的在质量降低很小的 ...
 - Java 1.0 类与对象
			
1.Java中main()的作用: a.测试真正的类 b.启动Java应用程序 2. Java程序只会让对象与对象交互 3.创建对象时存储在堆中,自动回收. 4.Java无全局变量 5.Java程序由 ...
 - 一步一步学EF系列【4、升级篇 实体与数据库的映射】live writer真坑,第4次补发
			
前言 之前的几篇文章,被推荐到首页后,又被博客园下了,原因内容太少,那我要写多点呢,还是就按照这种频率进行写呢?本身我的意图这个系列就是想已最简单最容易理解的方式进行,每篇内容也不要太多,这样初学者容 ...