HDU 1686 Oulipo(kmp)
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.
3
BAPC
BAPC
AZA
AZAZAZA
VERDI
AVERDXIVYERDIAN
1
3
0
kmp模板
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
#define N 1000005 char a[N],b[N];
int ans,next[N]; void getfail(char *b)
{
int i,j;
int len=strlen(b);
next[0]=-1;
i=0;j=-1;
while(i<len)
{
if(j==-1||b[i]==b[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
} void kmp(char *a,char *b)
{
int i,j;
int lena=strlen(a);
int lenb=strlen(b);
i=j=0;
while(i<lena)
{
if(j==-1||a[i]==b[j])
{
i++;
j++;
}
else
j=next[j]; if(j==lenb)
{
ans++;
j=next[j];
}
}
} int main()
{
int i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",b,a);
getfail(b);
ans=0;
kmp(a,b);
printf("%d\n",ans);
}
return 0;
}
HDU 1686 Oulipo(kmp)的更多相关文章
- hdu 1686 Oulipo (kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...
- HDU 1686 Oulipo(KMP)题解
题意:主串中能找到几个模式串 思路:超详细解释KMP KMP:针对这个代码,解释一下Fail数组的含义:T为主串,P为模式串,Fail代表失配值,即当P[j] != T[i]时,j要指向的位置为Fai ...
- HDU 1686 Oulipo(KMP变形求子串出现数目(可重))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给两个字符串A,B求出A中出现了几次B(计算重复部分). 解题思路:稍微对kmp()函 ...
- HDU 1686 Oulipo(KMP+计算匹配成功次数)
一开始总是超时,后来发现还是方法没找对,这个跟普通KMP不太一样的就是,KMP匹配成功的时候会完全跳过已经匹配成功的匹配段,至少我掌握的是.那么如何避免这样的问题呢,举个栗子啊 原串为ABABA,模式 ...
- HDU 1686 Oulipo (可重叠匹配 KMP)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 1686 Oulipo(优化的KMP)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 题解报告:hdu 1686 Oulipo(裸KMP)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- hdu 1696 Oulipo(KMP算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题意 查询字符串 $p$ 在字符串 $s$ 中出现了多少次,可重叠. 题解 KMP模板题. Ti ...
- POJ 题目3461 Oulipo(KMP)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26479 Accepted: 10550 Descript ...
随机推荐
- OTN&互换amp; P-OTN有效降低100G 网络成本 (两)
OTN互换& P-OTN有效降低100G 网络成本 (两) 在全球范围内.网流量的增长速度是空前的,导致此现象的缘由包含云服务的增长.移动宽带和基于互联网的视频点播服务的增长. Cisco估计 ...
- Linux C编程语言学习材料
C语言作为最基础的编程语言,30年虚弱的患病率. 无论是准备做 PHP/Java/Python/Golang 开发学习.C语言都是基础的,我们非常多基础非常小的互联网执行的开源软件服务都是C语言构筑, ...
- HDU 2012 素性
素性 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- nodejs显现events.js:72抛出错误
随着人们开始学习,我用nodejs过程中遇到如下列错误执行: events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EAD ...
- CacheManager
.Net缓存管理框架CacheManager Cache缓存在计算机领域是一个被普遍使用的概念.硬件中CPU有一级缓存,二级缓存, 浏览器中有缓存,软件开发中也有分布式缓存memcache, redi ...
- 读书时间《JavaScript高级程序设计》三:函数,闭包,作用域
上一次看了第6章,面向对象.这里接着看第7章. 第7章:函数表达式 定义函数有两种方式:函数声明.函数表达式 //函数声明 function functionName(arg0,arg1,arg2){ ...
- SqlServer 添加列并赋值
有个需求,需要给某张表添加一列并且赋值,分解需求,一共分两部走: 添加列 赋值 两个功能都不难,很快实现. --add column alter table Med_Summary_Template ...
- SQL Server系统数据库备份最佳实践
原文:SQL Server系统数据库备份最佳实践 首先了解主要的系统数据库: 系统数据库 master 包含登录信息和其他数据库的核心信息 msdb 存储作业.操作员.警报.备份还原历史.数据库邮件信 ...
- HDU 2112 HDU Today (Dijkstra算法)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 左右TS分析流
字节.在TS流里能够填入非常多类型的数据.如视频.音频.自己定义信息等.他的包的结构为,包头为4个字节,负载为184个字节(这184个字节不一定都是有效数据.有一些可能为填充数据). 工作形式: 由于 ...