大概就是裸的AC自动机了

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue> using namespace std; #define MAXN 130
class node
{
public:
node *fail;
node *next[MAXN];
int ind;
node ()
{
fail=;
ind=;
memset(next,,sizeof(next));
}
};
char s1[][];
char s2[];
int cnt[];
node *root;
void Insert(char *s,int id)
{
node *p=root;
while(*s)
{
int ind=*s-' ';
if(p->next[ind]==NULL)
p->next[ind]=new node;
p=p->next[ind];
s++;
}
p->ind=id;
}
queue<node *>q1;
void Build()
{
q1.push(root);
root->fail=NULL;
while(!q1.empty())
{
node *p=NULL;
node *now=q1.front();
q1.pop();
for(int i=;i<MAXN;i++)
{
if(now->next[i])
{
if(now==root)
now->next[i]->fail=root;
else
{
p=now->fail;
while(p)
{
if(p->next[i])
{
now->next[i]->fail=p->next[i];
break;
}
p=p->fail;
}
if(p==NULL)
now->next[i]->fail=root;
}
q1.push(now->next[i]);
}
}
}
}
void dfs(node *p)
{
for(int i=;i<MAXN;i++)
if(p->next[i])
dfs(p->next[i]);
delete p;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{ root=new node;
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++)
{
scanf("%s",s1[i]);
Insert(s1[i],i);
}
Build();
scanf("%s",s2);
int len=strlen(s2);
node *p=root;
for(int i=;i<len;i++)
{
int ind=s2[i]-' ';
while(p->next[ind]==NULL&&p!=root)
p=p->fail;
p=p->next[ind];
if(!p)
p=root;
node *now=p;
while(now!=root)
{
if(now->ind)
{
cnt[now->ind]++;
}
now=now->fail;
}
}
for(int i=;i<=n;i++)
{
if(cnt[i])
printf("%s: %d\n",s1[i],cnt[i]);
}
dfs(root);
}
return ;
}

AC自动机 HDU 3065的更多相关文章

  1. 数据结构--AC自动机--hdu 2896

    病毒侵袭 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  2. AC自动机 HDU 2896

    n个字串 m个母串 字串在母串中出现几次 #include<stdio.h> #include<algorithm> #include<string.h> #inc ...

  3. 从0开始 数据结构 AC自动机 hdu 2222

    参考博客 失配指针原理 使当前字符失配时跳转到另一段从root开始每一个字符都与当前已匹配字符段某一个后缀完全相同且长度最大的位置继续匹配,如同KMP算法一样,AC自动机在匹配时如果当前字符串匹配失败 ...

  4. AC自动机 HDU 2222

    t n个字串 1个母串 求出现几个字串 字串可能重复 #include<stdio.h> #include<algorithm> #include<string.h> ...

  5. (17/34)AC自动机/后缀数组/后缀自动机(施工中)

    快补题别再摸鱼了(17/34) 1.AC自动机 #define maxnode 1000010 #define maxsize 26 struct ahocT{ int ch[maxnode][max ...

  6. hdu 3065 AC自动机

    // hdu 3065 AC自动机 // // 题目大意: // // 给你n个短串,然后给你一个长串,问:各个短串在长串中,出现了多少次 // // 解题思路: // // AC自动机,插入,构建, ...

  7. AC自动机 - 多模式串的匹配运用 --- HDU 3065

    病毒侵袭持续中 Problem's Link:http://acm.hdu.edu.cn/showproblem.php?pid=3065 Mean: 略 analyse: AC自动机的运用. 这一题 ...

  8. HDU 3065 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...

  9. hdu 3065 AC自动机(各子串出现的次数)

    病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

随机推荐

  1. SimpleSSO:使用Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端

    目录 前言 OAuth2.0简介 授权模式 (SimpleSSO示例) 使用Microsoft.Owin.Security.SimpleSSO模拟OpenID认证 通过authorization co ...

  2. C# - 计时器Timer

    System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...

  3. [函数] Firemonkey Windows 重新计算 Font Baseline

    计算字型 Baseline 是一个不常用的函数,但如果想要显示不同大小文字下方对齐,就得用它来计算字型的 Baseline 才行,如果计算不准,显示的文字就会高高低低不整齐. 在 Firemonkey ...

  4. ActiveMQ 简单搭建

    ========== ActiveMQ ============== JMS : topic : 一对多: 发布订阅: 不保证数据是否被接受: 不存储topic信息: Queue : 一对一: 点对点 ...

  5. MAC远程连接服务器,不需要输入密码的配置方式

    cd ~/.ssh #没有则需要创建一个. mkdir ~/.ssh ssh-keygen -t rsa cd ~/.ssh scp id_rsa.pub root@IP地址:~/.ssh/id_rs ...

  6. react-echarts之折线图的显示

    react中想要实现折线图和饼图的功能,需要引入react-echarts包,然后再实现折线图的功能.我这里引用的版本是:0.1.1.其他的写法参echarts官网即可.下面详细讲解的是我在react ...

  7. 如何利用FineBI做财务分析

    很多企业随着业务规模的增长,传统的财务分析方式采用手工摘取数据的方式,难以快速地对企财务经营状况作出及时分析和预测.现在业务人员通过使用自助式BI工具做财务分析已经成为流行,每个人都希望自己做报表,快 ...

  8. Sencha, the nightmare!

    基础 创建一个应用程序 sencha -sdk /path/to/sdk generate app %name% /path/to/app 跑起来 cd /path/to/app sencha app ...

  9. installshield使用教程

    从Visual Studio 2012开始,微软就把自家原来的安装与部署工具彻底废掉了,转而让大家去安装使用第三方的打包工具“InstallShield Limited Edition for Vis ...

  10. http参数的封装(后台接受参数的场景)

    场景 不管是任何web框架作为一个web的开发人员必须要搞明白control层如何接受各种参数. 下面就根据我们公司的系统架构(nutz)来进行一下场景描述.各位小伙伴也可以根据这些 场景自己去总结一 ...