HDU 1686 Oulipo(kmp)

支付宝H5支付唤醒协议全解析:从alipays://到动态orderSuffix的抓取与拼接 本文深入解析支付宝H5支付唤醒协议,从alipays://协议设计到动态orderSuffix参数的抓取与拼接,详细介绍了支付宝H5支付的底层机制。内容包括协议架构剖析、动态令牌生成与捕获、浏览器兼容性解决方案以及安全机制设计,为开发者提供全面的技术指南和实践建议。 阅读详情

Problem Description
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:

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.

 

Input
The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

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.
 

Output
For every test case in the input file, the output should contain a single number, on a single line: the number of occurrences of the word W in the text T.

 

Sample Input
3 BAPC BAPC AZA AZAZAZA VERDI AVERDXIVYERDIAN
 

Sample Output
1 3 0
 

Source


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;
}






电力系统设计实战:如何用ETAP绘制一次接线图并优化供电方案 本文详细介绍了如何使用ETAP软件进行电力系统一次接线图的绘制与供电方案优化。从基础环境配置到主接线拓扑构建,再到典型接线方式的对比分析与智能优化,为工业与民用电力系统设计提供实用指南。通过ETAP的可靠性分析和动态仿真功能,帮助工程师选择最优供电方案,提升系统可靠性和运维效率。 阅读详情

相关推荐

从模拟到实战:移远EC800M单片机MQTT接入OneNet全流程解析

本文详细解析了移远EC800M单片机通过MQTT协议接入OneNet平台的全流程,涵盖环境准备、模拟设备搭建、硬件迁移、数据交互调试及性能优化等关键步骤。针对常见问题如AT指令缓冲区溢出、心跳间隔设置等提供实战解决方案,帮助开发者高效实现物联网设备稳定接入。

weixin_29215815的博客 431

hdu 1686 Oulipo(KMP)

题目链接:hdu 1686 Oulipo 题目大意:给出两个字符串W, T,问说T字符串中有几个子串和W字符串匹配。 解题思路:KMP,只不过在找到匹配串的时候不能直接跳出或者说让p=0,应该让p = next[p]。 #include #include const int N = 1000005; const int M = 10005; int n,

不慌不忙、不急不躁 912

Unity UGUI深度优化

Unity UGUI优化相关

不定时分享所学所得,包括游戏开发和其他收获! 2717

【kmp字符串匹配】hdu 1686 Oulipo

hdu 1686 Oulipohttp://acm.hdu.edu.cn/showproblem.php?pid=1686问题描述:字符串匹配次数暴力复杂度O(n×m),无谓的比较过多;kmp算法能优化到O(n+m),直接套板思路kmp_count()返回匹配成功的次数参考代码 #include<iostream> #include<cstdio> #include<cstdlib> #includ

Hacker_vision 478

抖音无水印视频解析全攻略:从原理到2025实战工具推荐

短视频创作和素材整理绕不开一个基础需求:如何从抖音等平台获取不带水印的清晰视频。这背后涉及的其实是常见的链接解析与播放地址还原技术——平台对外分发带水印的地址,但源视频文件往往存在可访问的公开入口。理解这一原理,不仅能帮我们判断工具是否安全,也能避免在搜索“抖音视频解析”、“无水印视频下载”时踩坑。无论是剪辑师收集二创素材、运营人员备份品牌内容,还是普通用户保存高清视频,掌握一套稳定、合规的下载方法都很有价值。本文从水印生成机制讲起,梳理了网页工具、插件、脚本等不同实现形态的优缺点,并给出2025年仍然有效

weixin_42666036的博客 440

解决西门子Step 7 basic 找不到许可证问题

你在使用博图软件是否遇到过Step 7 basic 找不到许可证的问题呢!不言怕,今天我就来告诉你该如何处理吧!看步骤: 1.删除原授权的License: 打开Automation License Manager应用,然后我们可以发现仅有的License Key前面有一个时钟,说明它已经过期不可用,我们就要去寻求新的Key. 打开“我的电脑”,选择C盘,点击上方查看 点击选项–>查看 然...

让技术没有门槛 14万+

HDU-1686- Oulipo KMP匹配

POJ-3461 Oulipo PJ的女朋友是一个书法家,喜欢写一些好看的英文书法。有一天PJ拿到了她写的纸条,暗示要送给他生日礼物。PJ想知道自己想要的礼物是不是就是她送的,于是想看看自己想要的在纸条中出现了多少次。 Input 第一行输入一个整数代表数据的组数 每组数据第一行一个字符串 W代表PJ想要的礼物, 包含英语字符 {‘A’, ‘B’, ‘C’, …, ...

Anoyer的博客 422

NR PUCCH(二)PUCCH format 2/3/4

继续看PUCCH2/3/4:PUCCH format 0和1所携带的信息bits少,UCI bits2bits,信息bit需要经过编码等过程下面分别来看。

ModemProtocol的博客 537

HDU - 1686 Oulipo(KMP模板题)

HDU - 1686 Oulipo #include<cstdio> #include<cstring> char a[10010],b[1000010]; int p[10010]; int n,m,c; void getnext() { int i=0,j=-1; memset(p,-1,sizeof p); while(i<n) { if(j==-1||a[i]==a[j]) p[++i]=++j; else j=p[j]; } } void kmp

00后的博客 278

【异常】OpenClaw 连接异常This site can‘t be reached 127.0.0.1 refused to connect Try: Checking the proxy

在访问OpenClaw相关服务时,浏览器提示如下异常信息,无法正常加载页面:Try:补充说明:该报错仅出现于本地访问场景(127.0.0.1为本地回环地址),涉及OpenClaw核心服务的本地连接交互,无外部网络及敏感信息泄露风险。

奶爸的编程之路,也就一周冷个三天 1483

自然语言处理:长文本场景下的关键词抽取实践

自然语言处理:长文本场景下的关键词抽取实践

丨汀、的博客 2076

【KMP】HDU 1686 Oulipo

哈希和KMP两种解法。颜文字缺失qwq

L_X_ 240

三态门Multisim电路仿真——硬件工程师笔记

三态门原理及应用摘要 三态门是具有高电平(1)、低电平(0)和高阻态(Z)三种输出的逻辑电路,通过使能端(EN)控制状态切换。高阻态时输出端等效断路,避免信号冲突。其核心应用包括: 总线系统:多设备共享总线时,仅使能选中设备的三态门,其余保持高阻态,防止干扰。 数据选择器:利用三态门切换多路输入信号,简化电路设计。 实现方式分两种: TTL三态门(三极管构成):低电平使能有效,仿真验证输出逻辑与高阻态。 MOS三态门(MOS管构成):高电平使能有效,仿真显示使能信号控制输出状态。 文中还附硬件工程师笔试面试

XU157303764的博客 2006

HDU - 1686 Oulipo KMP

Oulipo Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter ‘e’. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fai

weixin_51996479的博客 323

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU 1686 Oulipo(KMP)

题目链接:点击打开链接 KMP超级水的模板题...... // HDU 1686 Oulipo.cpp 运行/限制:124ms/1000ms #include #include #include using namespace std; char w[10005], t[1000005]; int Next[10005]; void MP() { int n = strlen(w);

不忘初心 488

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Hdu 1686 Oulipo[kmp]

题目链接:点击打开链接 这道题是裸的kmp。前两天对kmp学习了几天,感觉就是,next数组(也叫前缀数组),有点难实现。 不过照书打出来的很是简洁。 #include #include #include #include using namespace std; const int N=10003; const int M=1000004; char substring[N]

996

hdu1686 Oulipo kmp

题目传送门 思路:kmp模板,稍微修改下    #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1000100; char p[maxn],t[maxn]; in...

weixin_30338497的博客 138

Oulipo HDU - 1686 KMP

问题: The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tou...

HXX904的博客 320

KMP HDU 1686 Oulipo

The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s

zero 294

HDU 1686 Oulipo KMP

题意:给出一个模式串和一个待匹配串,求模式串在待匹配串中出现的次数 思路:KMP匹配成功后答案+1,返回fail位置继续匹配直到匹配到待匹配串尾 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<vector> #include&l...

qq_42397248的博客 187

HDU 1686 Oulipo [KMP]

Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:  Tout avait Pair no

Kelisiya 257

Oulipo HDU - 1686(KMP牛逼)

我写这个博客是不是感觉我很牛逼,不不,很菜的,只不过是将思路记下来而已。kmp我是很多都是套模板来A题,对于其中的本质思想,还不是很透彻,所以 给出大佬的博客 :大佬博客 求模式串在待匹配串的出现次数。 Input 第一行是一个数字T,表明测试数据组数。 之后每组数据都有两行:第一行为模式串,长度不大于10000;第二行为待匹配串,长度不大于1000000。所有字符串只由大写字母组成。 ...

博客 330

【题解】Oulipo HDU - 1686⭐⭐ 【KMP】

Oulipo HDU - 1686 求模式串在待匹配串中的出现次数。 Input 第一行是一个数字T,表明测试数据组数。之后每组数据都有两行: 第一行为模式串,长度不大于10,000; 第二行为待匹配串,长度不大于1,000,000。(所有字符串只由大写字母组成) Output 每组数据输出一行结果。 Examples Sample Input 4 ABCD ABCD SOS SOSOSOS CD...

Suprit's blog 477

HDU 1686Oulipo ———————Hash or KMP

Oulipo OulipoTime Limit: 3000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22302&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 8608 ...

鸿杰 的博客 275

HDU - 1686 Oulipo 简单KMP

HDU - 1686 Oulipo 题意 给定一个单词和一个字符串,求单词在字符串中出现的次数 思路 将单词当作模式串求 next(文中用 nxt 表示),把包含模式串最后一个字母所对应的前后缀也求出来(如果有n个字符则求到nxt[n]),根据最后的这个 nxt[n] 的值我们将知道与模式串相同的前缀在文本串的下一个位置。 AZA AZAZAZA AZA的nxt值为: -1 0 -...

没有梦想何以远行 388

hdu 1686 Oulipo (KMP)

OulipoTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22615 Accepted Submission(s): 8746 Problem DescriptionThe French author Georges P...

dggnqzt6462的博客 97

hdu1686 Oulipo【kmp】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题意:给你字符串W和T,让你求W在T中出现了多少次,可重叠的计算(见样例) 解析:每次匹配完的时候cnt++,然后让j=nex[j]#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> usi

22h's Blog 473
上一篇: ZOJ 2319 Beautiful People(LIS二分法+路径输出)
下一篇: HDU 1711 Number Sequence(kmp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值