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

Ubuntu 上 1Panel 的安装与高效运维实践 本文详细介绍了在Ubuntu系统上安装和高效运维1Panel面板的完整实践指南。内容涵盖了一键安装、Docker容器可视化部署、计划任务自动化以及网站数据库管理等核心功能,并提供了安全加固、资源监控与数据备份等进阶技巧,旨在帮助用户快速搭建并管理一个强大易用的服务器环境。 阅读详情

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


东方财富个股实时行情爬虫实战:从入门到精通,手把手教你构建股票数据采集系统 在量化投资、股市分析和数据挖掘等领域,获取实时、准确的股票行情数据是第一步也是至关重要的一步。东方财富网作为国内最大的财经门户网站之一,提供了丰富的股票数据和实时行情接口。本文将带你从零开始,构建一个完整的东方财富个股实时行情爬虫系统,涵盖股票代码遍历、JSON接口分析、反爬虫策略应对、数据持久化存储等核心技术点。目录前言一、项目背景与目标1.1 为什么要爬取东方财富数据?1.2 项目目标1.3 技术栈二、接口分析与逆向工程2.1 寻找真实数据接口2.2 简化接口2.3 字段含义对照表三、股票代码获取。 阅读详情

相关推荐

STM32F103+W5500网络通信

STM32F103+W5500网络通信一、W5500模块(一)W5500以太网模块介绍(二)模块排针功能表二、 modbus协议(一)modbus协议原理(二)Modbus 通讯方式1.Modbus三种通讯方式2.在Modbus网络上传输3.以太网(modbus tcp/ip)三、参考资料 一、W5500模块 (一)W5500以太网模块介绍 D-W5500 EVB以太网模块是一款基于WIZnet W5500芯片的以太网模块,且性价比高的以太网模块。W5500是一款全硬件TCP/IP嵌入式以太网控制器,为

”一只特立独行的猪“的博客 1万+

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

基于微信小程序的垃圾分类系统,附源码

垃圾分类小程序管理员功能有个人中心,管理员管理,意见反馈管理,视频类型管理,垃圾类型管理,新闻类型管理,论坛信息管理,环保视频管理,环保知识管理,垃圾信息管理,环保新闻管理,用户管理,知识问答试卷管理,试题管理,测试管理,轮播图管理。用户可以在微信小程序上面注册登录,查看各种环保信息和垃圾信息,还可以参加知识问答等操作。垃圾分类小程序的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。

Java徐师兄的博客 2080

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的博客 420

Simulink小白必看:用Simscape轻松搭建二阶倒立摆模型(附完整参数配置)

本文为Simulink初学者提供了使用Simscape Multibody模块库,从零开始搭建二阶倒立摆非线性物理模型的完整实战教程。文章详细讲解了如何通过物理组件(如刚体、关节)直观建模,替代复杂的数学推导,并涵盖参数配置、仿真调试及模型线性化方法,帮助读者快速掌握这一高效的物理建模路径。

grpc6streamer的博客 1049

从零构建:Simulink与PX4的快速原型开发实战

本文详细介绍了如何利用Simulink与PX4进行四旋翼无人机的快速原型开发,涵盖环境搭建、动力学建模、控制器设计、仿真验证及自动代码生成全流程。通过实战案例展示姿态控制器的实现与调试,帮助开发者高效完成从算法设计到硬件部署,显著提升开发效率并降低试错成本。

plant的博客 325

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

UG\NX二次开发 替换部件引用集UF_ASSEM_replace_refset

替换部件引用集UF_ASSEM_replace_refset,需要替换成“完整部件(Entire Part)”需要第三个参数传入空指针或者空字符串。

王牌飞行员_里海的博客 262

Keywords Search(HDU-2222)

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 ha...

Alex_McAvoy的博客 624

PX4从放弃到精通(五):PX4中的姿态表示方法及转换关系

文章目录机体坐标系与地理坐标系一、pandas是什么?二、使用步骤1.引入库2.读入数据总结 机体坐标系与地理坐标系 在实际应用中,加速度计的测量轴是由运动平台安装固定此器件的轴向决定的。这些坐标轴就形成了载体坐标系,定义如下: 坐标原点设在载体质心(这样可简化运动方程的推导); y轴指向载体前方,称为横滚轴,横滚角以y轴为起始旋转轴而得到,符合右手定则; x轴与y轴夹角90°,指向载体横向,称为俯仰轴,俯仰角以x轴为起始旋转轴而得到,符合右手定则; z轴与x轴、y轴构成右手笛卡儿坐标系,指向载体垂直方向

超维空间科技的博客 8123

把 SM30 用顺:从表设计到权限与传输,全面掌握 SAP Table Maintenance Generator

摘要 SAP的Table Maintenance Generator(TMG)是为配置表维护需求设计的经典工具,能够生成标准化的维护对话框(SM30)。它支持单表、维护视图(多表关联)和视图簇(导航式维护)三种维护对象类型。使用TMG前需注意三个关键设置:1)表维护权限选项;2)交付类(决定数据传输行为);3)客户端字段配置。通过SE54/SE11生成维护对话框时,需选择维护类型(一步/两步)和记录例程(控制传输)。TMG生成的对象包含函数组、屏幕和处理模块,但部分标准框架不可修改。实际应用中,可通过参数事

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 182

A - Keywords Search HDU - 2222

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 descriptio...

Jack_zhuiyi的博客 341

回归预测 | MATLAB实现TCN时间卷积神经网络多输入单输出回归预测

回归预测 | MATLAB实现TCN时间卷积神经网络多输入单输出回归预测

机器学习之心的博客,关注并私信文章链接,获取对应文章源码和数据。 2495

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 1037

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

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...

蜡笔小新冲鸭!!! 207

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

【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 411

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 965

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、付费专栏及课程。

余额充值