hdu2222 Keywords Search(AC自动机模板题)

STM32入门教程:智能马桶盖控制 通过编写相应的代码,您可以根据需要实现其他功能,例如座圈温度调节和液晶显示屏显示等。初始化配置 首先,使用STM32CubeMX创建一个新的工程,并选择您所使用的STM32单片机型号。智能马桶盖是一种集成了多种功能的智能家居设备,通过控制芯片来实现自动冲水、座圈加热、座圈温度调节等功能。在本教程中,我们将使用STM32系列单片机来控制智能马桶盖的各个功能。以上代码演示了如何通过STM32的GPIO控制引脚来控制智能马桶盖的冲水和座圈加热功能。写代码 接下来,我们将通过编写代码来控制智能马桶盖的各个功能。 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=2222

Keywords Search

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25141    Accepted Submission(s): 8224


Problem Description
In the modern time, Search engine came into the life of everybody like Google, Baidu, etc.
Wiskey also wants to bring this feature to his image retrieval system.
Every image have a long description, when users type some keywords to find the image, the system will match the keywords with description of image and show the image which the most keywords be matched.
To simplify the problem, giving you a description of image, and some keywords, you should tell me how many keywords will be match.
 

Input
First line will contain one integer means how many cases will follow by.
Each case will contain two integers N means the number of keywords and N keywords follow. (N <= 10000)
Each keyword will only contains characters 'a'-'z', and the length will be not longer than 50.
The last line is the description, and the length will be not longer than 1000000.
 

Output
Print how many keywords are contained in the description.
 

Sample Input
  
1 5 she he say shr her yasherhs
 

Sample Output
  
题目大意:给出n个单词,然后给出一段文章,问有多少个单词在文章中出现过。
思路:套上AC自动机模板
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<queue>
using namespace std;
struct Trie
{
	int next[500010][26],fail[500010],end[500010];
	int root,L;
	int newnode()
	{
		for(int i=0;i<26;i++)
			next[L][i]=-1;
		end[L++]=0;
		return L-1;
	}
	void init()
	{
		L=0;
		root=newnode();
	}
	void insert(char buf[])
	{
		int len=strlen(buf);
		int now=root;
		for(int i=0;i<len;i++)
		{
			if(next[now][buf[i]-'a']==-1)
				next[now][buf[i]-'a']=newnode();
			now=next[now][buf[i]-'a'];
		}
		end[now]++;
	}
	void build()
	{
		queue<int>Q;
		fail[root]=root;
		for(int i=0;i<26;i++)
		{
			if(next[root][i]==-1)
				next[root][i]=root;
			else
			{
				fail[next[root][i]]=root;
				Q.push(next[root][i]);
			}
		}
		while(!Q.empty())
		{
			int now=Q.front();
			Q.pop();
			for(int i=0;i<26;i++) 
			{
				if(next[now][i]==-1)
					next[now][i]=next[fail[now]][i];
				else
				{
					fail[next[now][i]]=next[fail[now]][i];
					Q.push(next[now][i]);
				}
			}
		}
	}
	int query(char buf[])
	{
		int len=strlen(buf);
		int now=root;
		int res=0;
		for(int i=0;i<len;i++)
		{
			now=next[now][buf[i]-'a'];
			int temp=now;
			while(temp!=root)
			{
				res+=end[temp];
				end[temp]=0;
				temp=fail[temp];
			}
		}
		return res;
	}
};
char buf[1000010];
Trie ac;
int main()
{
	int T,n;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		ac.init();
		for(int i=0;i<n;i++)
		{
			scanf("%s",buf);
			ac.insert(buf);
		}
		ac.build();
		scanf("%s",buf);
		printf("%d\n",ac.query(buf));
	}
	return 0;
}


【2024遥感应用组一等奖】基于风云四号卫星的小时级大气气溶胶和颗粒物监测 最后,比较AGRI观测反射率和查找表计算的反射率反演得到的1小时分辨率AOD数据。然后,使用广泛应用的MODIS DT和DB产品进行对比,图 5显示了它们逐像元尺度的对比,AGRI LaGA算法可以捕捉亚洲地区AOD高低值空间分布格局,比如南亚次大陆、中南半岛、塔克拉玛干沙漠和华北平原是AOD高值区域(平均AOD高于0.3),中国西北、中国南方、中国东北和韩国地区为AOD中值地区(平均AOD在0.2到0.3之间),北纬45度以上以及日本地区为AOD低值区域(平均AOD小于0.2),与全球平均AOD值接近。 阅读详情

相关推荐

半桥LLC谐振变换器及同步整流MATLAB仿真(二)

接上文,半桥LLC谐振变换器及同步整流MATLAB仿真

qq_55203246的博客 4330

AC自动机

<br />HDOJ 2222<br /> <br />Problem DescriptionIn the modern time, Search engine came into the life of everybody like Google, Baidu, etc.<br />Wiskey also wants to bring this feature to his image retrieval system.<br />Every image have a long description,

phtniit的专栏 624

密码学小白必看:三大顶级会议论文下载与阅读指南(附完整资源链接)

本文为密码学初学者提供了系统获取和阅读三大顶级会议(Crypto、Eurocrypt、Asiacrypt)论文的实战指南。详细介绍了通过IACR官方渠道、ePrint预印本等权威资源免费下载论文的方法,并分享了高效筛选、精读核心章节及构建个人知识体系的具体策略,帮助读者快速切入密码学研究前沿。

weixin_28363123的博客 406

HDU2222-Keywords Search

Keywords Search Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to bring this feature to his image retrieval system. Ev...

Shaosen的博客 419

CTS实战:如何用set_sense优化时钟树平衡(附ICC2避坑指南)

本文深入探讨了在时钟树综合(CTS)中,如何正确使用`set_sense`命令优化时钟树平衡,并对比了其与`set_disable_timing`的本质区别。通过实战案例详细解析了`-stop_propagation`和`-clock_leaf`参数的应用场景,并提供了ICC2工具中的关键避坑指南,帮助后端工程师精准控制时钟拓扑,避免时序分析漏洞。

weixin_28933797的博客 459

如何理解Apollo模型参考自适应控制MRAC

最近有了解到百度无人驾驶Apollo项目中的横向控制有用到MRAC(Model Reference Adaptive Control),于是便详细研究了一下这个控制方法,在此总结一下心得。 什么是MRAC MRAC控制系统的基本结构图如下所示: 它由两个环路组成,由控制器和受控对象组成内环,这一部分称之为可调系统,由参考模型和自适应机构组成外环。实际上,该系统是在常规的反馈控制回路上再附加一个参考模型和控制器参数的自动调节回路而形成。在该系统中,参考模型的输出或状态相当于给定一个动态性能指标,(通常,参考模

zmhzmhzm的博客 6480

hdu 2222 Keywords Search(AC自动机)

目录问题分析代码 问题 hdu 2222 Keywords Search - https://acm.hdu.edu.cn/showproblem.php?pid=2222 分析 多模式匹配,AC自动机 trie树 fail树 last树 代码 /* hdu 2222 Keywords Search */ #include<bits/stdc++.h> using namespace std; const int MXN = 500010, MXL = 1000010, SIZE = 26;

jpphy0的博客 255

Qt 国产嵌入式操作系统实现文字转语音功能(ekho库)

Qt 国产嵌入式操作系统实现文字转语音功能(TTS)_tts驱动 转文字-优快云博客在继上篇文章之后,甲方粑粑不满意使用eSpeak发出的声音太难听了,这就不得不找个替代品,声音稍微好听了一些。使用ekho开源库。Ekho(余音)是一个免费、开源的中文语音合成软件。它目前支持粤语、普通话(国语)、诏安客语、藏语、雅言(中国古代通用语)和韩语(试验中),英文则通过Festival间接实现。Ekho支持Linux、Windows和Android平台。

希望能帮助大家,希望大家多多支持,你们的支持是我前进的动力。 2754

HDU2222 Keywords Search 题解&代码

题意:多组数据,每组数据有n个字符串作为字典,然后给出另外一个字符串,询问这个新的字符串中有几个字典中的单词。 多个匹配串对单字符串匹配,AC自动机是标准解法,算是测试模板了【笑 然而RE了一发WA了一发…没看清数据范围对于字典中的字符串建立trie树和fail指针,然后对待匹配串匹配即可 有一些奇怪的小细节譬如字典中可能有多个相同字符串,以及判重问题…恩还是很好解决的嘛#include <i

Rainbow6174's home 610

YOLOv8 更换损失函数DIoU、EIoU、GIoU...Inner-IoU...

介绍了一些损失函数,并将其应用到yolov8训练中

分享一些自己改进代码的实例 888

基于Matlab的自动泊车系统开发:利用模糊控制实现智能停车解决方案的详细教程

Matlab是一种广泛应用于科学计算、工程建模与仿真的编程语言,其强大的工具箱和简洁的编程语法,使其成为开发自动泊车系统的理想选择。在开始编写代码之前,我们需要搭建Matlab的工作环境,并熟悉相关的工具箱,如Fuzzy Logic Toolbox,用于实现模糊控制。首先,确保你已经安装了Matlab软件,并加载了必要的工具箱。接下来,我们将逐步讲解如何在Matlab中实现自动泊车系统。

qq_38334677的博客 663

hdu 2222 Keywords Search(ac自动机水题)

Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 60242    Accepted Submission(s): 19853 Problem Description In the m

saber_acher的博客 449

YOLO26 正式发布源代码!极致速度优化方案, 面向工业级落地的目标检测模型!

YOLO26 作为 Ultralytics 公司于 2025 年 9 月发布的最新一代目标检测模型,在架构设计和技术实现上展现了显著的创新。本文深入分析了 YOLO26 的核心架构改进和技术原理,重点探讨了其在边界框回归、推理流程、损失函数设计和优化算法方面的突破性进展。

魔改工程师的博客 1244

hdu 2222 Keywords Search AC自动机模板题

Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to bring this feature to his image retrieval system. Every image have a long description, when users type some keywords to find

Lionel 1034

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

HDU2222 Keywords Search AC自动机模板题

Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 40607    Accepted Submission(s): 12928 Problem Description In the m

suyuxuan94的专栏 469

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

hdu-2222 Keywords Search ac自动机模板题

题目链接:https://vjudge.net/problem/HDU-2222 题意:给出 t 组数据,每组 n 个单词,再给出一个字符串,求这 n 个单词在字符串中出现的次数 思路:字符串多模版匹配,AC 自动机模版题 #include<bits/stdc++.h> using namespace std; #define ll long long const int maxn=5...

蜡笔小新冲鸭!!! 206

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【HDU 2222】Keywords Search AC自动机模板题

参考iwtwiioi的模板写出来的。上午gty讲的并没有听懂,只好自己慢慢对着模板理解。 在HDU上为什么相同的程序提交有时T有时A!!! 奉上sth神犇的模板(不是这道题): var ch:char; q,g,num:array [0..500001] of longint; st:string; son:array [0..500001,'a...

as2886089的博客 109

hdu 2222 Keywords Search AC自动机模板题

点击打开链接 题意:给出母串S 长度小于1e6 ,和字典, 问s中出现的dic单词有多少个? KMP是当字典中单词个数为1的情况 若单词个数很多 则复杂都O(n*m)显然不行 于是AC自动机就来啦~ 参考 AC自动机=KMP+Trie AC自动机主要就3个部分:      1 把所有模板插入到Trie中,建立大的状态转移图  2 建立失败指针:     根结点的失败指针指向自己

Masamiiiiii 367

HDU 2222 Keywords Search AC自动机模板题

题意: T组样例,N个子串,查询母串中子串出现的次数。 思路: ac自动机模板题 代码: (kuangbin模板) #include #include #include #include #include using namespace std; struct Trie { int next[500010][26],fail[500010],end[500010];

DT2131 409

HDU 2222 Keywords Search(AC自动机模板题)

学习AC自动机请戳这里:大神blog........ 自动机的模板: #include #include #include #include #include #include #include #include #include #include #include #include //形如INT_MAX一类的 #define MAX 100005 #define IN

Paradiser 962

HDU2222 Keywords Search(AC自动机模板题)

Problem Description In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to bring this feature to his image retrieval system. Every image have a long description, when users type some keywords to find

tomjobs的博客 481

keywords search (hdu 2222 AC自动机模板题)

AC自动机模板题:keywords search 网上说AC自动机的前置技能需要学习字典树和KMP,可我的感觉和KMP关系不太大,和字典树的数据结构类型关系倒是有密切联系,一定是我太菜了,所以理解不是那么深刻 AC自动机的关键:失配指针的构造 fail指针的构造是由bfs()分层遍历完成的,首先我们先将第一层压入队列,第一层的fail[]:0节点,然后寻找下一层的失配指针,下一层的失配指针...

yangzijiangac的博客 217

Hdu2222——Keywords Search(AC自动机模板题)

传送门 Keywords SearchTime Limit: 2000/1000 MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 76055&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 2...

wangyh1008的博客 457

HDU 2222 Keywords Search(AC自动机模板题)

题意:给出一个字符串和若干个模板,求出在文本串中出现的模板个数。 思路:因为有可能有重复的模板,trie树权值记录每个模板出现的次数即可。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #d

GODSPEED 800
上一篇: poj 1845 Sumdiv
下一篇: hdu5877 Weak Pair
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值