hdu 2222

AC自动机模板+例题(HDU2896+HDU3065+HDU2222) 病毒侵袭中(HDU2896) #include<map> #include<cmath> #include<queue> #include<vector> #include<cstdio> #include<string> #include<cstdlib> #include<cstring> ... 阅读详情

 终于把ac自动机学完了 先刷一个水题吧...

开始无限re。。 众哥帮我调的

#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;
#define FF(i,a)  for( int i = 0 ; i < a ; i ++ )
#define CC(m,what) memset(m,what,sizeof(m))

const int NODE = 600000;
const int CH = 26;
int chd[NODE][CH] , cnt;//结点个数
int word[NODE];//关键数组,记录每个单词尾结点的信息,每道题目都不一样
int fail[NODE];//传说中的失败指针
int Que[NODE];//辅助队列
int sw[150];//string swap每个字符对应的Index,方便模板化

void Ins(char *a, int val) {
 int p = 0;
 for(; *a ; a ++) {
  int c = sw[*a];
  if(!chd[p][c]) {
   //CC(chd[cnt] , 0);
   memset( chd[cnt], 0, sizeof( chd[cnt] ));
   word[cnt] = 0;
   chd[p][c] = cnt ++;
  }
  p = chd[p][c];
 }
 word[p] += val;
}

void AC() {
 int *s = Que , *e = Que;
 for ( int i = 0; i < CH; i++ )
    if(chd[0][i]) {
  fail[chd[0][i]] = 0;
  *e++ = chd[0][i];
 }
 while(s != e) {
  int p = *s++;
  for ( int i = 0 ; i < CH; i ++ ) {
   if( chd[p][i] ) {
    int v = chd[p][i];
    *e++ = v;
    fail[v] = chd[fail[p]][i];
    //word[v] += word[fail[v]];
    //对word[v]按word[fail[v]]里的内容进行处理
   } else {
    chd[p][i] = chd[fail[p]][i];

   }
  }
 }
}

void init ()
{
    fail[0] = 0;
 for( int i = 0; i < CH; i++ ) sw[i+'a'] = i;
//下面两句每次都必须初始化
 //CC(chd[0],0);
 memset( chd[0], 0,sizeof( chd[0] ));
 cnt = 1;
}

//AC()函数处理后 chd[p][i] 就是在p结点进行i转移到达的结点

char c[1000050];
int main() {

 int Case ;
 //freopen ("out.txt" , "r" , stdin );

 scanf("%d" , &Case );

 while ( Case -- )
 {
     int n;
     init();
     scanf("%d" ,& n );
     char str[100];
     for ( int i = 0; i < n; i ++ )
     {
            scanf("%s" , str );
            Ins( str, 1 );
     }
     AC();
        int ans = 0;
        scanf("%s" , c );
        int now = 0;
        char s ;
        int len = strlen ( c ) ;
        for ( int i = 0 ; i < len; i++ )
        {
            s = c[i];
            //cout << s << endl;
            now = chd[now][sw[s]];
            //cout << now << endl;
            ans += word[now];
            word[now] = 0;
            int p = now;
            while ( p != 0 )
            {
                ans += word[p];
                word[p] = 0;
                p = fail[p];
            }
            //cout << ans << endl;
        }
        printf("%d\n" , ans );
 }
    return 0;
}

Oracle EBS FA 创建成批增加执行时间长且报错 摘要 Oracle EBS系统在执行"创建成批增"请求时出现长时间运行并报错(ORA-00603和ORA-03114)。 阅读详情

相关推荐

基于R语言的DICE模型实践技术应用;预测不同减排路径下的经济增长、碳排放量、气候变化程度以及社会福利变化

DICE模型是一个动态综合气候经济模型,由诺贝尔经济学奖得主William Nordhaus开发,用于评估气候变化对经济的影响以及不同减排政策的经济成本和效益。以下是一个关于DICE模型在气候变化影响评估中的实际应用案例,结合R语言代码进行讲解。

KY_chenzhao的博客 866

【hdu3065-病毒侵袭持续中】AC自动机

【hdu3065-病毒侵袭持续中】AC自动机 题意:给定一些只含大写字母的病毒串,再给一个文本串,问文本串中每个病毒串各出现了多少次。 题解: 就是用AC自动机,在每个节点末尾有个id记录是哪个单词的末尾,然后如果同时是多个单词的末尾就用一个next数组链状记录当前id的下一个值。多组数据坑死人。坑死人。 1 #include&...

qq_25768269的博客 161

jmeter问题系列:Begin size 0 is not equal to fixed size 5

Begin size 0 is not equal to fixed size 5 ,问题的解决

雨水的早晨的博客 2411

hdu 3065 病毒侵袭持续中 //AC自动机

<br /> <br />病毒侵袭持续中Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 866    Accepted Submission(s): 293<br /><br /><br />Problem Description小t非常感谢大家帮忙解决了他的上一个问题。然而病毒侵袭持续中。在小t的不懈努力下,他发现了网路中的“万恶之源”

hqd_acm的专栏 984

【AI+教育】别再让 Cursor 只当编辑器了!4 步解锁 Claude 官方技能!

本文介绍了在Windows环境下通过OpenSkills工具在Cursor中调用Claude AI技能的方法。主要内容包括:1)安装Node.js环境;2)全局安装OpenSkills工具;3)安装Claude官方技能库;4)通过AGENTS.md文件同步技能;5)在Cursor中直接调用技能完成Excel、PPT等任务。文章提供了详细的操作步骤和示例,帮助用户快速上手使用AI技能提升工作效率。

奶爸的编程之路,也就一周冷个三天 751

米哈游 AI产品经理面试题精选:10道高频考题+答案解析(附PDF)

米哈游是全球知名游戏开发商,以《原神》《崩坏》系列著称,专注二次元文化与AI技术创新。本文整理了10道AI产品经理面试题,涵盖Transformer架构、智能NPC设计、机器学习应用、AIGC产品规划等核心领域。题目既考察技术理解(如RAG原理、多模态模型),又关注产品落地(游戏平衡性优化、伦理安全),同时强调跨团队协作能力。参考答案均结合米哈游业务场景,体现技术驱动与玩家体验并重的产品思维,展现AI在游戏行业的创新应用前景。

ZHHHHH15的博客 679

hdu-3065(AC自动机)

Hdu-3065 思路: 考虑所有的ASCII字符的情况,用26范围内可能出错。 #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; const in...

积少成多,水滴石穿 402

AI算力网络与通信领域流量分析:优化策略探讨_副本

今天的AI就像一个"超级吃货",每天要"吃"掉海量数据、“消耗"巨量算力——训练一个千亿参数的大模型,可能需要上万块GPU同时工作数周,其间产生的数据传输量足以填满数百万个1TB硬盘。这些GPU和计算节点通过网络连接形成"AI算力网络”,而数据在节点间的流动就是"通信流量"。如果把算力比作AI的"肌肉",那流量就是"血液"——血液不通畅,肌肉再强也使不上劲。

AI天才研究院 1198

HDU-3065-病毒侵袭持续中(AC自动机)

转载于:https://www.cnblogs.com/GrowingJlx/p/6642744.html

abcd12341abcd1234的博客 127

基于TL431与MOSFET的高效过压保护电路设计详解

本文详细解析了基于TL431与MOSFET的高效过压保护电路设计。通过TL431精准监测电压,驱动MOSFET作为主开关,实现快速可靠的电源保护。文章涵盖电路原理、参数计算、性能优化及实战调试要点,为电子设备提供了一套经典且成本低廉的过压保护解决方案。

weixin_29215391的博客 771

HDU3065(病毒侵袭持续中)字符串匹配-简单的AC自动机

/******************************************************* 题目大意: 给多串病毒和一个源码; 求每串病毒在源码中出现的次数; 算法思想: AC自动机; 给每串病毒一个编号; 当匹配成功后用visit数组记录该病毒出现的次数; ********************************************************/

始往流离,终彼成章。 1684

华为OD机试真题 新系统 9月16号 【园区基站节能部署规划】

华为OD机试真题 新系统【园区基站节能部署规划】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【园区基站节能部署规划】多语言题解。

qq_45776114的博客 352

HDU2222

HDU2222 题意 求目标串中出现了几个模式串. 思路 ac自动机模板题. 代码 #include<bits/stdc++.h> using namespace std; struct Trie{ int next[500010][26],fail[500010],end[500010]; int root,L; int newnode(){ ...

Do It Youself! 157

OV9734 DATASHEET,完整规格书

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

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

hdu_OJ_2222

// 题目:hdu_2222 // 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2222 // 状态:Accept /** * 这题是用字典树做的,效率不太高,其中还有很多地方有待优化 * * 缺陷:每个实例都重新建一颗字典树,没有释放资源,如果测试实例太多,将占用大量内存。 */ #include #include struct n

程书画的 BLOG 1794

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Hdu 2222 Keywords Search

package hdu; import java.util.ArrayDeque; import java.util.Scanner; /** * @description HDU 2222 Keyboards Search. * @technique AC自动机, 字典树。 * @version 1.2 * @date 20120727 * @time 20:2

Alex 493

HDU2222-Keywords Search AC自动机

HDU2222-Keywords Search AC自动机算法

P_rogrammer的专栏 742

HDU 2222 AC 自动机

题意 传送门 HDU 2222 题解 多模式匹配,裸的 ACACAC 自动机。 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define maxn 10000 #define maxl 1000005 struct node { int cnt, a[26];

neweryyy的博客 216

HDU 2222 Keywords Search【ACAM】

HDU 2222 Kerwords Search 代码风格模仿自:USETC每周算法讲解,AC自动机,郭老师! 输入一个T,对于每一个T给你一个n,接下来输入P个模式串,然后给你一个L串,L中出现了多少P中的串。 这是一道比较基础的AC自动机问题,我只不过是为了不想用板子而直接写,因此写此博文。 将容易遗漏或者写错的地方进行了注释的标注,用于提示自己,也用于与大家进行分享。 #include&lt...

Irish_Moonshine的博客 259

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自动机

ACoder 293

Hdu2222Keywords Search

Hdu2222存一发AC自动机模板…【代码】#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <queue> #define N 500005 #define INF 1LL<<60 using namespace std; typedef long long ll; ll r

Heret1c 423

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

hdu 2222 Keywords Search

hdu 2222 Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 71419 Accepted Submission(s): 24370 Problem Description In

wuxiaowu547的博客 222

hdu 2222 Keywords Search

题目链接:hdu 2222 Keyworld Serach 字符串的多模式匹配 题意:给你n个单词和一个主串,让你求有多少单词在主串中出现 #include #include #include #include #define maxn 1000005 using namespace std; int head,tail;//队列头尾指针 struct node { node *fa

parting_soul的专栏 317

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

weixin_30648963的博客 77
上一篇: poj 2391
下一篇: 位运算 转自matrix67神牛
Sov_Matrix
博客等级 码龄17年 0粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值