/****************************************************************************************************
改了下HDU2222的代码,今天才知道原来可见的ASCII码是128个,害得我MLE了一次~
****************************************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
//#include <hash_map> //Visual C++ lib
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define LEN(s) static_cast<int>( strlen((s)) )
typedef long long LL; //GNU C++
typedef unsigned long long ULL;
//typedef __int64 LL; //Visual C++ 2010
//typedef unsigned __int64 ULL;
typedef double LF;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
//typedef hash_map<int, int>::iterator HMI;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL; //15f
const double oo = 10e9;
const double eps = 10e-9;
const double PI = acos(-1.0);
const int MAXN = 100004;
const int MAXM = 10004;
const int MAXC = 128;
int n, m;
char str[MAXM];
struct Node
{
Node *next[MAXC];
Node *fail;
int cnt;
}trie[MAXN], *root;
int ncnt;
queue<Node *>Q;
void initTrie()
{
root = trie;
ncnt = 1;
for (int i = 0; i < MAXC; ++i)
{
root->next[i] = NULL;
}
root->fail = NULL;
root->cnt = 0;
return ;
}
Node* createNode(Node *crt)
{
for (int i = 0; i < MAXC; ++i)
{
crt->next[i] = NULL;
}
crt->fail = NULL;
crt->cnt = 0;
return crt;
}
void insert(char *ch, int id)
{
Node *ptr = root;
int nxt;
while (*ch != '\0')
{
//nxt = *ch - 'a';
nxt = *ch;
if (NULL == ptr->next[nxt])
{
ptr->next[nxt] = createNode( &trie[ncnt++] );
}
ptr = ptr->next[nxt];
++ch;
}
ptr->cnt = id;
return ;
}
void buildAC_automation()
{
while (!Q.empty())
{
Q.pop();
}
Q.push(root);
Node *crt, *nxt, *ptr;
while (!Q.empty())
{
crt = Q.front();
Q.pop();
for (int i = 0; i < MAXC; ++i)
{
nxt = crt->next[i];
if (nxt != NULL)
{
for (ptr = crt->fail; ptr != NULL; ptr = ptr->fail)
{
if (ptr->next[i] != NULL)
{
nxt->fail = ptr->next[i];
//nxt->cnt += nxt->fail->cnt; //
break ;
}
}
if (NULL == ptr)
{
nxt->fail = root;
}
Q.push(nxt);
}
else
{
if (root == crt)
{
crt->next[i] = root;
}
else
{
crt->next[i] = crt->fail->next[i];
}
}
}
}
return ;
}
bool query(char *str, int rk)
{
int id, top = 0, S[105];
Node *ptr = root, *ptt;
while (*str != '\0' && top < 3)
{
//id = *str - 'a';
id = *str;
ptr = ptr->next[id];
/*for (ptt = ptr; ptt != NULL && ptt->cnt != -1; ptt = ptt->fail)
{
res += ptt->cnt;
ptt->cnt = -1;
}*/
for (ptt = ptr; ptt != NULL && ptt->cnt != 0; ptt = ptt->fail)
{
S[top++] = ptt->cnt;
}
++str;
}
if (!top)
{
return false;
}
sort(S, S + top);
printf("web %d:", rk);
for (int i = 0; i < top; ++i)
{
printf(" %d", S[i]);
}
puts("");
return true;
}
void ace()
{
int res;
char ch[202];
while (scanf("%d%*c", &n) != EOF)
{
initTrie();
for (int i = 1; i <= n; ++i)
{
gets(ch);
insert(ch, i);
}
buildAC_automation();
res = 0;
scanf("%d%*c", &m);
for (int i = 1; i <= m; ++i)
{
gets(str);
res += query(str, i);
}
printf("total: %d\n", res);
}
return ;
}
int main()
{
ace();
return 0;
}
相关推荐
Spring AI实现RAG(检索增强生成)详解与实践
支持多种文件格式的文档加载实现高效的向量存储和检索构建智能的问答系统提供可追溯的知识服务RAG技术为AI应用提供了强大的知识增强能力,使得模型能够基于实际文档生成准确、可靠的回答。
hdu2896(AC自动机)
这个题有一个非常坑的点 就是网址不一定是小写字母!! 还有就是这个题卡空间卡到令人窒息 子节点数组开到130即可 节点最大个数210*500即可 但是要注意不是小写字母的话下文代码处原本的s[j]-'a'要变为s[j]-'\0' (不如叫RE-ME-WA自动机好了) #include<iostream> #include<cstdio> #include<...
目标检测数据集 第059期-基于yolo标注格式的水果李子检测数据集(含免费分享)
李子作为中国三大水果之一,种植历史超 3000 年,在市场中占据重要地位。传统李子种植、施肥、采摘依赖大量人力,存在资源浪费、产量估算不准、采摘时机难把控等问题。此前,农业领域缺乏针对 “未成熟李子” 的专用数据集,现有水果检测数据集多聚焦于成熟果实(如苹果、柑橘),且未覆盖李子种植的复杂自然场景。在使用该数据集进行学术研究时,应遵守相关的学术规范,引用该数据集的来源,尊重数据集创作者的劳动成果。,用于训练改进型模型,解决李子精准检测的核心痛点。
HDU2896 HDU3065(AC自动机)
HDU2896 题意 求目标串中出现了几个给定的子串. 思路 ac自动机模板题(). 代码 #include<bits/stdc++.h> using namespace std; struct Trie { int next[105010][130],fail[105010],end[105010]; int root,L; int newnode()...
零基础玩转IndexTTS2:5分钟搭建个人语音克隆工具(支持B站同款情感语音)
本文详细介绍了如何零基础使用IndexTTS2快速搭建个人语音克隆工具,支持B站同款情感语音。IndexTTS2作为自回归零样本TTS系统,突破传统技术限制,实现精准时长控制和丰富情感表达。通过HuggingFace在线演示,用户可轻松克隆音色并调节情感参数,适用于自媒体配音、有声书朗读等场景。
Geneformer实战:如何用Hugging Face Transformers快速搭建单细胞转录组分类模型
本文详细介绍了如何使用Geneformer和Hugging Face Transformers快速搭建单细胞转录组分类模型。通过环境准备、数据预处理、模型加载与配置、训练Pipeline构建等步骤,帮助读者掌握基于Transformer架构的单细胞数据分析技术,提升分类准确率和效率。
hdu 2896 病毒侵袭 ac自动机
1 /* 2 hdu 2896 病毒侵袭 ac自动机 3 从题意得知,模式串中没有重复的串出现,所以结构体中可以将last[](后缀链接)数组去掉 4 last[]数组主要是记录具有相同后缀模式串的末尾节点编号 。本题中主要是计算每一个模式串 5 在主串中有没有出现过,而不是计算出现过多少次,所以将last[]数组省掉.... 6 */ ...
YOLOv8改进 | 主干篇 | 利用MobileNetV1替换Backbone(轻量化网络结构)
本文给大家带来的改进机制是MobileNetV1,其是专为移动和嵌入式视觉应用设计的轻量化网络结构。这些模型基于简化的架构,并利用深度可分离卷积构建轻量级深度神经网络,其引入了两个简单的全局超参数,用于在延迟和准确性之间进行有效的权衡。实验表明,MobileNets在资源和准确性的权衡方面表现出色,并在多种应用(如对象检测、细粒度分类、面部属性识别和大规模地理定位)中展现了其有效性,这个模型非常适合轻量化的读者来使用。适用检测目标:轻量化网络结构适合轻量化的读者。
【AC自动机】hdu2222 hdu2896 hdu3065 zoj3430 poj2778 hdu2243
AC自动机用于多个模式串与多个母串的匹配。 第一步:根据模式串建立字典树int len=strlen(w), r=root; for(int i=0;i<len;++i) { if(tree[r].ch[w[i]])r=tree[r].ch[w[i]]; else r=tree[r].ch[w[i]]=++cnt; } ++tree[r].c
基于 MFC C++ 的心电监测客户端
4. **报警功能**:使用 `PlaySound` 播放报警音(需准备 `alert.wav` 文件),界面显示报警状态。
【LDPC-7】LLR量化位宽对LDPC译码性能的影响分析——以最小和译码算法为例进行matlab仿真
最小和译码算法的步骤如下:最后译码结果如果满足或者完成所有迭代次数,则译码算法停止迭代,否则继续进行译码迭代操作。
HDU 2896 病毒侵袭 AC自动机裸题
题目来源:HDU 2896 病毒侵袭 题意:求文本串中有多少个模式串 并且输出下标 思路:直接ac自动机 然后数组记录在输出 我日写了半天结果函数没调用 找了半天错误 你要长记性啊 这种错误犯了好几次了啊 笨蛋 #include #include #include using namespace std; const int maxn = 10010; char a[maxn];
在 ABAP CDS View 里把 Conversion Functions 用到极致:FLTP 精度、单位换算、货币换算与小数位处理的工程化实践
数据格式转换在真实项目中比业务逻辑更容易引发问题。ABAP CDS中的转换函数(如FLTP_TO_DEC、UNIT_CONVERSION、CURRENCY_CONVERSION和DECIMAL_SHIFT)可帮助在数据库层统一数据口径,避免应用层重复处理。这些函数支持数值精度治理、单位换算、货币转换和小数位调整,能显著提升报表性能并减少逻辑分散。通过将格式转换前移到数据模型层,可以确保服务层和UI层的数据一致性,同时降低接口传输错误风险。
HDU 2896 病毒侵袭 (AC自动机)
题目地址:HDU 2896 AC自动机模板题。 记录每个终止节点的ID。然后在自动机里找就行了。 代码如下:#include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set
精雕软件(JDpaint) 5.5 绿色版
精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
病毒侵袭 HDU - 2896(AC自动机)
思路:在建树的时候吧每个病毒的编号加进去,在match的时候找到对应的值,因为最多3个病毒,所以找到3个直接退出。 #include <cstdio> #include <cstring> #include <algorithm> #include <set> #include<iostream> #include<vector> #include<queue> //#include<bits/stdc++.h&g..
visio安装包
Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。
AC自动机板子(hdu2222)&(hdu2896)
参考博客:https://blog.youkuaiyun.com/bestsort/article/details/82947639 AC代码:hdu2222 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<queue> #in...
怀旧版电脑GBC模拟器
再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。
AC自动机(hdu 2896 hdu 3065)
题目:hdu 2896 题意:中文题目,可自己理解,简单说就是给定一些子字符串,再给出一些母字符串,找出母字符串中包含哪些子字符串 题解:AC自动机模板题 代码: 动态申请: #include #include #include #include #include #include #define MAX 59999 using namespace std; struct Node {
病毒侵袭 HDU - 2896(AC自动机)
病毒侵袭 题目链接:HDU - 2896 题意:N个病毒编码,M个网站编码,问每个网站编码中包含那几种病毒; 思路:多串匹配多串,很明显是AC自动机,而且是个模板题; 之前写使用的指针写的,结果ML了,然后就找到了一个不用指针的模板,将指针改为了二维数组,这样就不会ML了; #include <bits/stdc++.h> using namespace std; int...
HDU 2896 病毒侵袭 AC自动机
思路:对每个字符串在Trie树上找一遍即可。注意:理论应该有10w个节点,但是10w个MLE了,所以开8w也能过。 http://acm.hdu.edu.cn/showproblem.php?pid=2896 /********************************************* Problem : HDU 2896 Author : NMfloat
AC自动机(hdu-2896)
hdu-2896 思路: 注意从小到大,然后先标记,然后依次输出。 #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; const int maxn ...
HDU 2896 病毒侵袭(AC自动机)
HDU 2896 病毒侵袭(AC自动机) 题意:给你一组模板,然后在给你多个文本,要你去匹配文本,看看每个文本中都出现了哪些模板然后输出即可. 分析:本题的模板不会重复,题目中已说明. 不过本题的字符是所有ASCII码可见字符,所以sigma_size=128. AC代码:
hdu2896 AC自动机
hdu2896: 题意:有一些串是病毒串(模式串),标号1~n,给出m个待匹配串,问每个模式串中有哪些病毒串,从小到大输出,并求共有多少待匹配串含有病毒串 就是将AC自动机的模板改了一下,用模式串结尾结点记录下这是哪个模式串的结尾,在遍历时再排序输出即可 1 #include<stdio.h> 2 #include<string.h> 3 #incl...
hdu2896 AC自动机
#include #include #include #include #include #include #include //AC自动机模板题(动态建立) using namespace std; char a[205], b[10010]; int h, c[10]; struct trie {
hdu 2896 病毒侵袭 (AC自动机)
hdu 2896 病毒侵袭 基础AC自动机
1239



被折叠的 条评论
为什么被折叠?



