hdu 2222 ac自动机模板题

【源码+文档】C++实现关键字检索系统 这是题目的要求,虽然看似多此一举比较繁琐,但是它实现了将输入内容存放于文件、从文件中读取内容两个操作,很好地将此题建立在了文件输入输出的基础上,并且能够保存用户输入的文字,一举两得。作为一个关键字检索系统,我们让用户在终端输入多段英语段落(也即多行英文),为了明确标识结束符,我们以单独一行的一个“0”作为终端输入的结束符。在InitFile::InputText()中,先让用户输入英文段落,以单独一行的0作为结束标志,使用getline读入一行,每读入一行,都全部转换为小写然后储存到打开的文件之中。 阅读详情

Keywords Search

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


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 <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;

#define maxn 500010

struct Trie
{
    int next[maxn][26], fail[maxn], endd[maxn]; 
    int root, L;
    int newnode()
    {
        for(int i=0; i<26; i++)
            next[L][i]=-1;
        endd[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'];
        }
        endd[now]++;
    }
    void build()
    {
        queue<int> que;
        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;
            que.push(next[root][i]);
        }

        while(!que.empty()){
            int now=que.front(); que.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];
                que.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+=endd[temp];
                endd[temp]=0;
                temp=fail[temp];
            }
        }
        return res;
    }
};

char buf[maxn<<1];
Trie trie;
int main()
{
    int t;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        trie.init();
        for(int i=0; i<n; i++){
            scanf("%s", buf);
            trie.insert(buf);
        }
        trie.build();

        scanf("%s", buf);
        int ans=trie.query(buf);
        printf("%d\n", ans);
    }
    return 0;
}





有史以来最小的GIF/png/jpg/jpeg 昨天我对图像进行了 base64 编码,这样我就可以将它发送到 CouchDB 以测试我正在为客户编写的一些代码。它让我想起了我之前在远程服务器上设置 cookie 时所做的事情。基本上,一个小的 PHP 脚本被放在远程服务器上,它接受几个 GET 参数并根据它们的值设置一些 cookie。然后脚本输出一个 1x1 的透明 GIF。本地服务器上的 PHP 脚本生成了一个 IMG 标签,该标签链接到该图像并根据本地服务器上的 COOKIES 设置参数。 阅读详情

相关推荐

时空图神经网络实战:T-GCN在交通流量预测中的深度解析

本文深度解析了时空图神经网络T-GCN在交通流量预测中的实战应用。通过结合图卷积网络(GCN)和门控循环单元(GRU),T-GCN有效捕捉交通数据的时空依赖性,相比传统方法降低30%以上预测误差。文章详细介绍了T-GCN的核心技术、工程实践和优化策略,为智能交通系统提供有力工具。

weixin_29038537的博客 267

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

龙迅LT9611UXC芯片简介:Dual-Port MIPI DSI/CSI to HDMI2.0 with Audio

龙迅半导体推出的LT9611UXC是一款高性能MIPI转HDMI2.0转换器,支持DSI/CSI接口转换,兼容多种视频格式(RGB/YCbCr),最高支持4K@60Hz输出。该芯片集成音频处理(I2S/SPDIF)、色彩空间转换和3D功能,适用于机顶盒、电视盒子等消费电子及车载设备。提供工业级(-40℃~+85℃)和车规级(AEC-Q100认证)版本,采用QFN64封装。

MB16698594834的博客 1333

【hdu 2222】Keywords Search 中文题意&题解&代码(C++)

AC自动机入门题,模板题

曾经追梦的happy时光 1510

VSCode下载、安装+C语言环境配置(超详细)

ps:我的更改部分:"D:/BaiduNetdiskDownload/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64。③ 找到【系统变量】中的【Path】变量 ---- 双击打开后,将刚刚复制的地址添加进去 ---- 点击【确定】;① 双击【此电脑】---- 点击【属性】---- 进入到下面这个界面,单击【高级系统设置】;② 进入到 系统属性界面 ---- 点击【环境变量】,进入环境变量页面;并进行安装,安装成功后,打开VSCode;

weixin_48820458的博客 1万+

UWB灵犀遥控器方案介绍

UWB灵犀指向遥控器的技术原理和方案介绍

xiongdauwb的博客 3898

人大金仓license到期解决办法

人大金仓license到期解决方法

qq_38905741的博客 2343

【Arduino+ESP32专题】CP2102串口自动下载电路

CP2102串口自动下载电路原理是什么?

一点硬件 2955

【题解】Keywords Search(AC自动机)

题面 【题目描述】 给定n个长度不超过50的小写字母组成的单词,以及一篇长为m的文章,问有多少个单词在文章出现。 输入 第一行一个整数T,表示测试数据组数。 对于每组测试数据,每一行一个整数n,接下去n行n个单词,最后一行输入一个字符串,表示文章。 【输出】 对于每组测试数据,输出一个数,表示有多少个单词在文章中出现。 【样例输入】 1 5 she he say shr her yasherhs 【样例输出】 3 提示 n<=104,m<=106n<=10^4,m<=10^6n&

_BOSS_的博客 1018

生成自定义工具栏

我们生成了和VBA时代几乎一样的常用的工具栏。用WPF也可以完成以后的插件开发,界面控件编写基本靠自己绘画,还有用代码去控制,代码结构像HTML,做过网站的应该可以很快入手。其它后台C#代码除了对控件代码的控制外,和WinForm基本相同,但目前来看用WPF是生成自定义工具栏的较好的办法。当然,你也可以在工具栏命令中调用WinForm程序,对Coreldraw进行操作,这也应该是比较高效的办法,下次会讨论。资源的加入是本次调试的难点之一,我们的目标是让图片资源嵌入到程序中去,不必去电脑文件目录去调用;

力先生C#程序开发 1374

万字长文告诉新手如何学习Python图像处理(上篇完结 四十四) | 「Python」有奖征文

这篇文章是图像处理的最后一篇文章,后面我们将进入新的章节。图像处理文章主要讲解的图像处理方法包括图像几何运算、图像量化采样、图像点运算、图像形态学处理、图像增强、图像平滑、图像锐化、图像特效、图像分割、傅里叶变换与霍夫变换、图像分类等。个人感觉如果你是编程初学者、Python初学者或图像处理爱好者,这个系列真心适合你学习,并且这篇文章算是Python图像处理的学习路线,希望您喜欢。

杨秀璋的专栏 2万+

HDU 2222(AC自动机模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串。问匹配串中含有多少个模式串。注意模式串有重复,所以要累计重复结果。 解题思路: AC自动机模板题。 一开始使用LRJ的坑爹静态模板,不支持重复的模式串。 在做AC自动机+DP的时候,扒了zcwwzdjn大神的动态优化(失配指向root)写法,以及借鉴了网上的AC...

weixin_33869377的博客 113

OpenClaw 在 Docker 容器中的部署实战——零配置启动

本文介绍了OpenClaw在Docker容器中的快速部署方法,对比了本地部署与容器化部署的优势。通过官方镜像和Docker Compose两种方式,5分钟即可完成部署,并详细讲解了配置管理方案(挂载配置文件和环境变量)。文章还提供了飞书集成配置方法,以及生产环境下的日志管理、资源限制、健康检查等优化建议。最后包含常见问题排查指南,帮助开发者快速实现OpenClaw的容器化部署。

刘一说的IT专栏 904

hdu 2222AC自动机模板题

点击打开链接 题意:问前面给的所有串在最后一个串出现的次数 思路:这道题是AC自动机入门必做的题,所以没什么好说的,是个模版题,推荐一个大神写的算法详解,不懂得可以看一看,反正我是看他的稍稍懂了点 [html] view plain copy #include stdio.h>   #include string.h>   #incl

The_star_is_at的博客 384

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

hdu 2222 AC自动机模板题

首先学KMP   推荐《算法导论》以及本人的KMP博文 http://blog.youkuaiyun.com/u011026968/article/details/10382659 在学Trie  这个其实不难,随意找点资料就行 然后开始学AC自动机  http://www.cppblog.com/mythit/archive/2014/03/09/80633.html#206110  这个博文的讲解很好

Pilgrim 1363

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

HDU 2222 ac自动机入门模板题

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

大咸鱼。。。 440

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdu2222 ac自动机模板题

ac自动机模板

Code of Duty 563

AC自动机模板题 HDU - 2222

Keywords SearchHDU - 2222 贴个vj的链接https://vjudge.net/problem/HDU-2222 题意:T组数据,n个单词,再给你一个串,看有几个单词在这个串里面出现过 Sample Input 1 5 she he say shr her yasherhs Sample Output 3 #include &l...

dmep51250的博客 230

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

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 1033

hdu-2222 AC自动机模板题

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

ba82586628365094的博客 132

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

【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

hdu2222(AC自动机入门模板题)

题目链接:https://vjudge.net/problem/HDU-2222 Keywords Search 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 descript..

weixin_44757834的博客 321

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
上一篇: poj 1236 强连通分量+缩点
下一篇: poj 2778 AC自动机+dp矩阵快速幂
HuanTongH
博客等级 码龄12年 7粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值