[hdu1686] Oulipo【KMP】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1686
保存KMP模版,代码里P是模版串,next[]就是为它建立的。T是文本串,就是一般比较长的。next[i]表示i后缀的最长相等前缀在哪,字符串从1开始数(而不是0)。
#include <cstdio>
#include <cstring> const int maxn = 10005, maxm = 1000005; /* n for |Pattern|, m for |Text| */
/* |Pattern| is shorter than |Text| in general */ int kase, n, m, next[maxn];
char P[maxn], T[maxm]; /* build next[] for Pattern, not for Text!!! */
inline void get_next(void) {
next[0] = -1;
next[1] = 0;
int i = 1, j = 0;
while (i < n) {
while (j != -1 && P[i + 1] != P[j + 1]) {
j = next[j];
}
next[++i] = ++j;
}
}
inline int count(void) {
int i = 0, j = 0, rt = 0;
while (j < m) {
while (i != -1 && P[i + 1] != T[j + 1]) {
i = next[i];
}
++i;
++j;
if (i == n) {
++rt;
}
} return rt;
} int main(void) {
//freopen("in.txt", "r", stdin);
scanf("%d", &kase);
while (kase--) {
scanf("%s", P + 1);
n = strlen(P + 1);
scanf("%s", T + 1);
m = strlen(T + 1); get_next();
printf("%d\n", count());
}
return 0;
}
[hdu1686] Oulipo【KMP】的更多相关文章
- hdu 1686 Oulipo 【KMP】(计算模式串匹配的次数——与已匹配的字串可以有交集)
题目链接:https://vjudge.net/contest/220679#problem/B 题目大意: 输入一个T,表示有T组测试数据: 每组测试数据包括一个字符串W,T,T长度大于W小于100 ...
- 【KMP】【最小表示法】NCPC 2014 H clock pictures
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...
- 【动态规划】【KMP】HDU 5763 Another Meaning
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...
- HDOJ 2203 亲和串 【KMP】
HDOJ 2203 亲和串 [KMP] Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【KMP】Censoring
[KMP]Censoring 题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his ...
- 【KMP】OKR-Periods of Words
[KMP]OKR-Periods of Words 题目描述 串是有限个小写字符的序列,特别的,一个空序列也可以是一个串.一个串P是串A的前缀,当且仅当存在串B,使得A=PB.如果P≠A并且P不是一个 ...
- 【KMP】Radio Transmission
问题 L: [KMP]Radio Transmission 题目描述 给你一个字符串,它是由某个字符串不断自我连接形成的.但是这个字符串是不确定的,现在只想知道它的最短长度是多少. 输入 第一行给出字 ...
- 【kmp】似乎在梦中见过的样子
参考博客: BZOJ 3620: 似乎在梦中见过的样子 [KMP]似乎在梦中见过的样子 题目描述 「Madoka,不要相信QB!」伴随着Homura的失望地喊叫,Madoka与QB签订了契约. 这是M ...
- 【POJ3461】【KMP】Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
随机推荐
- Android Weekly Notes Issue #243
Android Weekly Issue #243 February 5th, 2017 Android Weekly Issue #243 本期内容包括: ConstraintLayout的动画; ...
- 配置composer代理
composer config -g repo.packagist composer https://packagist.phpcomposer.com
- hihocoder 挑战赛9 A.好配对(思维题目 防止超时)
#1123 : 好配对 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个序列a和b,每个序列中可能含有重复的数字. 一个配对(i,j)是一个好配对当从第一个序列中选 ...
- 动态注册BroadcastReceiver
1. [代码][Java]代码 package com.zjt.innerreceiver; import android.app.Service; import android.con ...
- html5--3.14 lable元素和label属性
html5--3.14 lable元素和label属性 学习要点 掌握label元素的使用 掌握label属性的使用 lable元素 用来为 input 元素定义标注(标记),建立一个与之相关联的标签 ...
- tensorflow 线性回归解决 iris 2分类
# Combining Everything Together #---------------------------------- # This file will perform binary ...
- Splay模板(序列终结者)
我只是一个存模板的,详细的请看这里http://blog.csdn.net/whai362/article/details/47298133 题目链接:http://www.codevs.cn/pro ...
- CodeForces768B:Code For 1 (分治)
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On hi ...
- table内 获取同一行 其他列的value
table内 获取同一行 其他列的value function move(obj,ud){ var code = document.getElementById("reportName&q ...
- Azure Key Vault (3) 在Azure Windows VM里使用Key Vaule
<Windows Azure Platform 系列文章目录> 本章我们介绍如何在Azure Windows VM里面,使用.NET使用Azure Key Vault 我们需要对Key V ...