HDU-1686 Oulipo
学习:重点理解这句话的意思: next[j]会告诉我们从哪里开始匹配 模板题。
Oulipo
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3612 Accepted Submission(s): 1428
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.
#include"stdio.h"
#include"string.h"
int next[],num;
char a[],b[];
int lena,lenb;
void get_next()
{
int i,j;
i=;next[]=-;j=-;
while(i<lenb)
{
if(j==-||b[i]==b[j])
{
i++;
j++;
if(b[i]==b[j])
{
next[i]=next[j];
}
else
{
next[i]=j;
}
}
else
{
j=next[j];
}
}
}
void kmp()
{
int i,j;
i=;
j=;
num=;
while(i<lena)
{
if(a[i]==b[j]||j==-)
{
i++;
j++;
}
else
{
j=next[j];
}
if(j==lenb)//当j==Lenb next[j]会告诉我们从哪里开始匹配
{
num++;
j=next[j];
}
}
printf("%d\n",num);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
getchar();
while(n--)
{
gets(b);
gets(a);
lena=strlen(a);
lenb=strlen(b);
get_next();
kmp();
}
}
return ;
}
HDU-1686 Oulipo的更多相关文章
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...
- HDU - 1686 Oulipo KMP匹配运用
id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - ...
- hdu 1686 Oulipo KMP匹配次数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...
- HDU 1686 - Oulipo - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...
- hdu 1686 Oulipo kmp算法
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目: Problem Description The French author George ...
- HDU 1686 Oulipo(KMP变形求子串出现数目(可重))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给两个字符串A,B求出A中出现了几次B(计算重复部分). 解题思路:稍微对kmp()函 ...
- hdu 1686 Oulipo (kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...
- HDU 1686 Oulipo , 同 POJ 3461 Oulipo (字符串匹配,KMP)
HDU题目 POJ题目 求目标串s中包含多少个模式串p KMP算法,必须好好利用next数组,, (kmp解析)——可参考 海子的博客 KMP算法 //写法一: #include<string ...
- HDU 1686 Oulipo(kmp)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- hdu 1686 Oulipo (kmp)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
随机推荐
- weewwe
http://blog.csdn.net/u013073524/article/details/25912891
- javascript闭包的理解
闭包是Javascript的一个难点,但也是一个很重要的知识点. 1.首先我们要知道变量作用域链 变量的作用域分两种:全局变量和局部变量.没有定义到任何函数中的变量为全局变量,在函数中定义的变量为局部 ...
- 九度OJ 1131 合唱队形 -- 动态规划(最长递增子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1131 题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合 ...
- [JS]Cookie精通之路
[JS]Cookie精通之路 转http://blog.163.com/neu_pdh1983/blog/static/572407020077310528915/ 发布:Cary 媒体:www.Ju ...
- c#代码自动修改解决方案下任意文件
命名空间 using EnvDTE;using EnvDTE80; private DTE2 _applicationObject; public void AutoAddControl(插件 v_f ...
- C# dataGridView不显示默认行的解决办法
当页面只有一个dataGirdView时,调用From的Activated函数,在Activated函数里调用以下两个函数,可清除默认选择行 private void From_Activated(o ...
- CoreGraphics --- CGContext
CGContext又叫图形上下文,相当于一块画布,以堆栈形式存放,只有在当前context上绘图才有效.iOS有分多种图形上下文,其中UIView自带提供的在drawRect:方法中通过UIGraph ...
- Java基础类型自动装箱(autoboxing)
Java SE 1.5 版本及之后,开始提供自动装箱功能. 自动装箱,将基础类型“包装”成一种类型: 基本类型 --> 包装器类 如下过程可触发自动装箱过程: Integer count = ...
- 修改.htaccess实现子目录绑定示例分享
<IfModule mod_rewrite.c>RewriteEngine On RewriteBase /# 把 www.jb51.net改为你要绑定的域名.# 如果是域名:Rewri ...
- Introduction to Gaussian Processes
Introduction to Gaussian Processes Gaussian processes (GP) are a cornerstone of modern machine learn ...