Oulipo----poj3461(kmp模板)
题目链接:http://poj.org/problem?id=3461
和 减花布条 的题对比一下;
求s2中s1的个数kmp模板;
- #include<stdio.h>
- #include<iostream>
- #include<algorithm>
- #include<string.h>
- using namespace std;
- const int N = 1e6+;
- char s1[N], s2[N];
- int n, m, ans;
- int Next[N];
- void GetNext()
- {
- int i = , j = -;
- Next[i] = j;
- while(i<n)
- {
- if(j==- || s2[i] == s2[j])
- Next[++i] = ++j;
- else
- j = Next[j];
- }
- }
- void kmp()
- {
- int i = , j = ;
- while(i<m)
- {
- if(j==- || s1[i] == s2[j])
- i++,j++;
- else
- j = Next[j];
- if(j == n)
- {
- ans++;
- j=Next[j];
- }
- }
- }
- int main()
- {
- int T;
- scanf("%d", &T);
- while(T--)
- {
- scanf("%s%s", s2, s1);
- m = strlen(s1);
- n = strlen(s2);
- GetNext();
- ans = ;
- kmp();
- printf("%d\n", ans);
- }
- return ;
- }
Oulipo----poj3461(kmp模板)的更多相关文章
- poj 3461 Oulipo(KMP模板题)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36903 Accepted: 14898 Descript ...
- POJ3461 KMP 模板题
最近忙着考研复习,所以刷题少了.. 数据结构昨天重新学习了一下KMP算法,今天自己试着写了写,问题还不少,不过KMP算法总归是理解了,以前看v_JULY_v的博客,一头雾水,现在终于懂了他为什么要在算 ...
- HDU 1686:Oulipo(KMP模板,子串出现次数)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- POJ Oulipo KMP 模板题
http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4 ...
- Oulipo HDU 1686 KMP模板
题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...
- POJ Oulipo(KMP模板题)
题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...
- HDU 1686 Oulipo(kmp)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- POJ 3461 Oulipo(——KMP算法)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
随机推荐
- la4730(并查集+树状数组)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=30& ...
- love2d--glsl03噪声
由于一些glsl的教程都是3d的,而love是2d的,所以之后以示例为主,我会收集 一些love的shader,分类讲解. 此文简译自love2d社区博客,这里略去作者的自我介绍. 像素着色器入门 示 ...
- [shell]C语言调用shell脚本接口
Use popen if you want to run a shell command and want the parent process to be able to talk to the c ...
- C# 静态构造函数使用
当我们想初始化一些静态变量的时候,就需要用到静态构造函数了.这个静态构造函数属于类,而不属于实例,就是说这个构造函数只会被执行一次,即:在创建第一个实例或引用任何静态成员之前,由.NET自动调用. 现 ...
- sql 使用整理
今天使用视图查询东西,为了方便直接select * 查出来的都行全部都错乱了,看来sql 超过20个以上的字段为了效率和安全,禁止用select * -------------查一个表的所有字段的-- ...
- 【BZOJ】1610: [Usaco2008 Feb]Line连线游戏(几何)
http://www.lydsy.com/JudgeOnline/problem.php?id=1610 两种做法,一种计算几何,一种解析几何,但是计算几何的复杂度远远搞出解析集合(虽然精度最高) 计 ...
- ThinkPHP跳转与重定向的区别
跳转: 浏览器认为: 当前URL请求成功, 重新请求新的URL. 浏览器会 记录当前的URL 和 新的URL 在请求历史记录中. 回退, 是可以回退到, 当前的URL上的. (无论 success, ...
- ArcGIS -- ArcSDE Lock request conflicts with an established lock
1.查询下列表是否有数据 select * from sde.state_locks; select * from sde.object_locks; select * from sde.layer_ ...
- shell脚本学习总结02--数组
bash同时支持普通数组个关联数组,普通数组只能使用整数作为数组的索引,关联数组可以使用字符串作为数组的索引. 数组的定义方法: 在单行中使用一列值定义一个数组 [root@new ~]# array ...
- m2014_c->c语言容器类工具列
转自:http://www.cnblogs.com/sniperHW/category/374086.html cocos2dx内存管理 摘要: cocos2dx基于引用计数管理内存,所有继承自CCO ...