HDU2222Keywords Search ac自动机

安装Tailscale 如果返回 /usr/bin/tailscale 或类似路径,说明已安装但 sudo 可能找不到它。如果 which tailscale 没有输出,说明安装失败,重新执行安装步骤。Tailscale 的后台服务 tailscaled 必须运行。检查 tailscaled 服务是否运行。检查 tailscale 命令是否存在。 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=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 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

 

3

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int maxnode=500000+100;
const int sigma_size=26;
int ans;
struct AC_Automata
{
    int ch[maxnode][sigma_size];
    int val[maxnode];//用于保存当前单词输入了几遍,当用find扫描文本的时候,只要遇到该单词就+val[i]且让vis[i]=false,使得下次遇到该模板不会重复计算
    int f[maxnode];
    int last[maxnode];
    bool vis[maxnode];//非单词节点vis=0,单词节点vis=1.如果用find找到了单词i节点,那么vis=0.
    int sz;
    void init()
    {
        sz=1;
        memset(ch[0],0,sizeof(ch[0]));
        vis[0]=false;
        last[0]=f[0]=val[0]=0;
    }
    void insert(char *s)
    {
        int n=strlen(s),u=0;
        for(int i=0;i<n;i++)
        {
            int id=s[i]-'a';
            if(ch[u][id]==0)
            {
                vis[sz]=false;
                ch[u][id]=sz;
                memset(ch[sz],0,sizeof(ch[sz]));
                val[sz++]=0;
            }
            u=ch[u][id];
        }
        vis[u]=true;
        val[u]++;
    }
    void print(int i)
    {
        if(val[i])
        {
            if(vis[i])
            {
                ans+=val[i];
                vis[i]=false;
            }
            print(last[i]);
        }
    }
    void find(char *s)
    {
        int n=strlen(s),j=0;
        for(int i=0;i<n;i++)
        {
            int id=s[i]-'a';
            while(j && ch[j][id]==0) j=f[j];
            j=ch[j][id];
            if(val[j]) print(j);
            else if(last[j]) print(last[j]);
        }
    }
    void getFail()
    {
        queue<int> q;
        f[0]=0;
        for(int i=0;i<sigma_size;i++)
        {
            int u=ch[0][i];
            if(u)
            {
                last[u]=f[u]=0;
                q.push(u);
            }
        }
        while(!q.empty())
        {
            int r=q.front();q.pop();
            for(int i=0;i<sigma_size;i++)
            {
                int u=ch[r][i];
                if(!u) continue;
                q.push(u);
                int v=f[r];
                while(v && ch[v][i]==0) v=f[v];
                f[u]=ch[v][i];
                last[u] = val[f[u]]?f[u]:last[f[u]];
            }
        }
    }
};
AC_Automata ac;
const int MAXN=1000000+100;
char text[MAXN],word[100];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ans=0;
        ac.init();
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",word);
            ac.insert(word);
        }
        ac.getFail();
        scanf("%s",text);
        ac.find(text);
        printf("%d\n",ans);
    }
    return 0;
}

 

本地部署 pyvideotrans(视频翻译配音工具) 语音识别选择faster-whisper(本地),模型选择预先下载并保存的medium,然后选择好要处理的视频以及保存到的位置,这里我选择了一个名为why not的英文演讲视频,保存在桌面_vedio_out文件下。将附件中faster-medium.7z 和 faster-small.7z解压到项目中的models目录下, 解压后,目录中应该存在 models--Systran--faster-whisper-small。en.m4a|.wav = 原始视频中的音频文件(包含所有背景音和人声) 阅读详情

相关推荐

STM32H750实战:如何用CubeMX配置NAND Flash时序(附常见问题排查)

本文详细解析了STM32H750通过CubeMX配置NAND Flash时序的实战技巧,包括硬件连接、时序参数计算与优化策略,以及常见问题如RGB屏幕干扰、多片选冲突的解决方案。特别针对NAND Flash的时序配置和抗干扰设计提供了实用代码示例和优化建议,帮助开发者提升系统稳定性和性能。

weixin_29176179的博客 368

C++——AC自动机例题——Keywords Search(HDU2222)

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

McDonnell_Douglas的博客 1113

Anaconda 2026.07 安装配置完全指南:从下载到PyCharm整合

Python 环境管理一直是开发者绕不开的课题,而 Anaconda 作为集成了 conda 与 300+ 科学计算包的发行版,极大降低了环境配置门槛。其核心价值在于通过虚拟环境实现不同项目的依赖隔离,避免版本冲突。但在实际安装与配置过程中,用户常因版本差异、镜像源访问慢、与 IDE 集成不畅等问题陷入困境。本文以 Anaconda 2026.07 为例,系统讲解从官方渠道或国内镜像源下载、安全校验、安装选项分析、conda 命令初始化,到配置清华镜像源、创建指定 Python 版本的虚拟环境,再到与 Py

weixin_32520095的博客 457

AC自动机 模板 【HDU2222】 Keywords Search

AC自动机(Aho Corasick Automaton) 如果匹配字符串,一个模式串,一个匹配串,KMP就搞定了。 但是如果现在有多个模式串怎么办呢?每个模式串都处理一遍,再与匹配串匹配就太慢了,所以有了AC自动机,来解决这类问题。AC自动机可以看成是Trie树和KMP的结合体,具体的实现方式就是在每个节点处增添一个fail指针,作用与KMP中的失配时用的跳转数组差不多(虽然在匹配的大多数时候

Todobe 502

ubuntu20.04配置UR机械臂的仿真环境

gazebo和rviz中的机械臂的位姿是一样的,要实现同步控制,可以拖动rviz中的球移动到指定位置,点击plan观察路径规划,点击execute执行该路径规划,可以在gazebo和rviz中同步看到刚刚的路径规划运动,实现了简单的机械臂仿真环境搭建。这是因为catkin找的python版本为anaconda下面的版本,所以需要改为指定采用下面的命令,参考之前的。之后要source一下,才能读取到工作空间里的文件,以后每次打开终端进入工作空间都要执行该命令。时,一直不成功,解决办法可以看我之前写的。

weixin_48319333的博客 3499

实测昇腾310P跑Qwen3有多慢?手把手带你部署vLLM并记录性能数据

本文实测了昇腾310P在vLLM框架下部署Qwen3模型的性能表现,详细记录了2.5 tokens/s的生成速度及其技术瓶颈。通过环境搭建、基准测试和深度分析,揭示了计算资源利用率不足等关键问题,并提供了实用的优化技巧与监控方案,帮助开发者更好地理解和优化昇腾平台上的大模型部署。

weixin_28724319的博客 908

HDU2222-Keywords Search AC自动机

HDU2222-Keywords Search AC自动机算法

P_rogrammer的专栏 744

KUKA机器人与S7-1200 PLC实现Profinet通讯配置步骤详解

在工业自动化产线中,PLC与工业机器人之间的高效数据交换是控制逻辑落地的关键。传统硬接线方案在信号点多时布线复杂、故障排查困难,而现场总线技术通过一根网线即可实现主从设备间的周期通讯。Profinet作为主流工业以太网协议,由S7-1200作为IO Controller主站,KUKA机器人作为IO Device从站,在WorkVisual与TIA Portal中完成设备组态、I/O映射及信号分配,即可替代成捆电缆,稳定传输启停、状态及报警信号。这一方案适用于汽车、3C、物流等行业的自动化产线,尤其适合需要扩

weixin_42519985的博客 261

【AC自动机】Hdu2222:Keywords Search

Hdu 2222:Keywords SearchDescriptionIn 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

puck_just_me的blog 708

斗鱼直播间弹幕爬虫实战:WebSocket连接与实时数据采集

在数据驱动的时代,直播平台的弹幕数据蕴含着巨大的价值——用户行为分析、舆情监控、弹幕情感分析、直播热度评估等应用场景层出不穷。斗鱼作为国内领先的直播平台,其弹幕系统基于WebSocket协议实现实时双向通信。本文将带您从零开始,使用Python构建一个完整的斗鱼直播间弹幕爬虫系统。

2201_76125261的博客 146

Pre-suite 开发之MFi功能搭建

Pre-suite 固件中只有带无线硬件的Ezairo 7160sl才具备无线通信能力,其无线功能包括标准BLE 5.2 低功耗蓝牙功能以及非标准的低功耗无线音频流功能。Ezairo 7160sl 支持3种低功耗无线音频流协议:来自APPLE的MFi,来自Google的ASHA以及来自onsemi的remote mic。其中MFi音频流走的G.722编码的Mode1,速率为64kbps;而非MFi音频流走的G.722的Mode3,速率为48kbps.

SnowYang2017的博客 1507

HDU2222 Keywords Search + HDU2896病毒侵袭 AC自动机

虽然看明白了KMP和字典树,但是AC自动机还是没怎么理解QAQ... 附上讲解博客Orz:https://blog.csdn.net/qq_30346729/article/details/78835040                                https://www.cnblogs.com/cjyyb/p/7196308.html 1.HDU2222 Keyword...

A confused programmer 298

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

HDU2222 Keywords Search 【AC自动机】

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

Dream_maker的博客 355

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDU2222 Keywords Search —— AC自动机

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 Keywords Search Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 65272...

alince20008的博客 169

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

AC自动机 hdu2222 Keywords Search

传送门:点击打开链接 题意:给一个字典,再给一个查询串,问字典中的单词一共在这个查询串中出现了多少次。 思路:裸AC自动机。。第一次做,照着bin神代码写了个模板留着以后贴 #include #include #include #include #include #include #include #include #include #include #include #include #i

qwb的博客 854

hdu 2222 Keywords Search(AC自动机入门题)

昨晚开始想学AC自动机,然后尽早看了看算导的KMP。。。以前看过,忘差不多了。 今天看了看一个学习AC自动机的文章,磕磕绊绊理解了。 trie的建立很随意,关键是失败指针这个概念。稍微有点抽象。这个指针的建立,用到了BFS,引用那个文章的话 “  假设有一个节点k,他的失败

小媛在努力~ 2601

hdu2222 Keywords Search ac自动机

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int maxn=1e7+5; int cnt; struct node{ node *next[26]; node *fai

nankeyimeng的博客 1048

hdu2222 Keywords Search【AC自动机】

题意: t组数据,每次给你n个模式串,和一个长串,请问这个长串里面包含几个模式串 n的范围为1e4,每个模式串的长度不超过50,长串的长度不超过1e6 题解: AC自动机入门,也是我第一次写AC自动机 学习博客 模板用的是kuangbin的模板 要点: fail数组初始化都为0,而我的trie的根节点也为0 套路总结: 先初始化空的自动机,插入每个模式串,建立字典树,对建立完的字典树跑一遍bfs建...

OOOak 173

HDU2222 Keywords Search AC自动机

网址:https://vjudge.net/problem/HDU-2222 题意: 统计模式串在文本串的出现次数,文本串只含有小写字母。 题解: $AC$自动机的模板题,在$Trie$树上建出$Trie$图,然后查询的时候跳$fail$指针直到已访问结点或者根结点记录数量,标记已访问结点即可。 AC代码: #include <cstring> #inclu...

FairyTail0423的专栏 251

HDU 2222 Keywords Search【AC 自动机】

HDU 2222 Keywords Searchhttp://acm.hdu.edu.cn/showproblem.php?pid=2222大意:给出n个关键字,问在串str中出现了多少关键字。 如有5个关键字如下: 5shehesayshrher串str = "yasherhs" 那么当前str中包含3个关键字,分别为:"she","he","her"分析:AC 自动机 这里用...

a48634331的博客 141

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

HDU 2222 Keywords Search 题意:问文本串中出现了多少种模式串。 AC CODE【AC奥特曼板子题~】 #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include &l...

L_X_ 212

hdu 2222 Keywords Search AC自动机

AC自动机的裸题,不过需要注意几个地方,keywords中有重复的,而且模板中会重复出现keywords~ #include <cstdio> #include <queue> #define SIGMA_SIZE 26 #define MAXNODE 500100 using namespace std; int ch[MAXNODE][SIGM...

amily05200的博客 197

hdu 2222 Keywords Search (AC自动机)

视频地址  http://www.bilibili.com/video/av6295004/index_2.html 题目地址 http://acm.hdu.edu.cn/showproblem.php?pid=2222 简介地址 http://blog.csdn.net/niushuai666/article/details/7002823 AC自动机简介:  首

bushadid的博客 783

hdu 2222 Keywords Search //ac自动机

<br />Keywords SearchTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 7476    Accepted Submission(s): 2541<br /><br /><br />Problem DescriptionIn the modern time, Search engine came into the life

hqd_acm的专栏 1214

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 hav

I'm Growing 394

【HDU 2222】 Keywords Search AC自动机

Keywords Search Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 80824Accepted Submission(s): 28183 Problem Description In the modern t...

天才小熊猫的博客 309
上一篇: UVA 1449 Dominating Patterns (LA4670)ac自动机
下一篇: HDU4612Warm up 缩点加树的直径
桑榆207
博客等级 码龄9年 148粉丝 1070原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值