POJ3461:Oulipo——题解
http://poj.org/problem?id=3461
KMP板子,好久以前学过了,直接把板子粘上去即可。
#include<cstdio>
#include<cstring>
using namespace std;
char s1[];
char s2[];
int nxt[]={};
void getnext(int m){
int j=;
for(int i=;i<=m;i++){
while(j!=&&s2[j+]!=s2[i])j=nxt[j];
if(s2[j+]==s2[i])j++;
nxt[i]=j;
}
return;
}
int ans;
void KMP(int n,int m){
int j=;
for(int i=;i<=n;i++){
while(j!=&&s2[j+]!=s1[i])j=nxt[j];
if(s2[j+]==s1[i])j++;
if(j==m){
ans++;
j=nxt[j];
}
}
return;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
ans=;
memset(nxt,,sizeof(nxt));
scanf("%s%s",s2+,s1+);
int n=strlen(s1+),m=strlen(s2+);
getnext(m);
KMP(n,m);
printf("%d\n",ans);
}
return ;
}
POJ3461:Oulipo——题解的更多相关文章
- KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period
首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...
- poj3461 Oulipo(KMP模板)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17795 Accepted: 7160 Descripti ...
- POJ3461–Oulipo(KMP)
题目大意 给定一个文本串和模式串,求模式串在文本串中出现的次数 题解 正宗KMP 代码: #include<iostream> #include<cstring> #inclu ...
- poj3461 Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- POJ3461——Oulipo
1.题目大意:单字符串匹配问题 2.分析:经典KMP问题 存个模板QAQ #include <cstdio> #include <cstdlib> #include <c ...
- POJ-3461 Oulipo(KMP,模式串在主串中出现次数)
题意:给你两个字符串p和s,求出p在s中出现的次数. 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 我先想直接把p接到s前面,之后求Next数组对st ...
- POJ3461 Oulipo KMP算法
这个算法去年的这个时候就已经听过了,看毛片算法哈哈..不过理解它确实花了我很久的时间..以致于我一直很排斥字符串的学习,因为总觉得太难了,但是有些硬骨头还是要啃的,这个寒假就啃啃字符串还有一些别的东西 ...
- poj3461 Oulipo (KMP模板题~) 前面哪些也是模板题 O.O
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...
- POJ3461 Oulipo 字符串
正解:kmp/哈希 解题报告: 传送门! 这题其实就kmp板子,,,用来复习下kmp的太久没打了QAQ 所以kmp做法就不港了放个代码就是了QAQ #include<algorithm> ...
随机推荐
- Android 模拟器下载、编译及调试
Android 模拟器源码下载 Android 模拟器源码的下载与 Android AOSP 源码库的下载过程类似,可以参考 Google 官方提供的 Android 源码下载文档 来了解这个过程. ...
- cf#516A. Make a triangle!(三角形)
http://codeforces.com/contest/1064/problem/A 题意:给出三角形的三条边,问要让他组成三角形需要增加多少长度 题解:规律:如果给出的三条边不能组成三角形,那答 ...
- 微信小程序—day05
小程序云服务器--环境配置 本来想要买腾讯云的云服务器,作为小程序的服务端的.无奈,腾讯云卖的太贵了,比阿里云要贵一倍,想想还是算了. 但是,没有服务端的接受,小程序的一些功能是实现不了的.找了一圈, ...
- linux命令(实用!)
本文转载自网络 1.1 shell家族 shell:命令解释器,根据输入的命令执行相应命令. 察看当前系统下有哪些shell: cat /etc/shells 察看当前系统正在使用的shell ech ...
- lesson 17 The longest suspension bridge in the world
lesson 17 The longest suspension bridge in the world agreeable adj. 令人愉快的:适合的 = pleasant be located ...
- python中为什么 if/while/def/class语句需要冒号?
python中冒号主要用于增强可读性(ABC语言实验的结果之一).考虑一下这个: if a == b print(a) 与 if a == b: print(a) 注意第二种方法稍微容易一些.请进一步 ...
- jmeter链接数据库问题汇总
1.最新驱动下载: 驱动版本与mysql服务不兼容也是会报错的 下载地址:https://dev.mysql.com/downloads/connector/j/ 打开页面一直拉到页面底部,此处选择P ...
- HTMLTestRunner带饼图
# -*- coding: utf-8 -*- """ A TestRunner for use with the Python unit testing framewo ...
- SIG蓝牙mesh笔记5_Provisionging
目录 Bluetooth Mesh Provisioning Provisioning bearer layer Generic Provisioning PDU Bluetooth Mesh Pro ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...