首页 技术 正文
技术 2022年11月12日
0 收藏 417 点赞 3,786 浏览 2191 个字

病毒侵袭持续中

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10324    Accepted Submission(s): 3633

Problem Description小t非常感谢大家帮忙解决了他的上一个问题。然而病毒侵袭持续中。在小t的不懈努力下,他发现了网路中的“万恶之源”。这是一个庞大的病毒网站,他有着好多好多的病毒,但是这个网站包含的病毒很奇怪,这些病毒的特征码很短,而且只包含“英文大写字符”。当然小t好想好想为民除害,但是小t从来不打没有准备的战争。知己知彼,百战不殆,小t首先要做的是知道这个病毒网站特征:包含多少不同的病毒,每种病毒出现了多少次。大家能再帮帮他吗? Input第一行,一个整数N(1<=N<=1000),表示病毒特征码的个数。
接下来N行,每行表示一个病毒特征码,特征码字符串长度在1—50之间,并且只包含“英文大写字符”。任意两个病毒特征码,不会完全相同。
在这之后一行,表示“万恶之源”网站源码,源码字符串长度在2000000之内。字符串中字符都是ASCII码可见字符(不包括回车)。 Output按以下格式每行一个,输出每个病毒出现次数。未出现的病毒不需要输出。
病毒特征码: 出现次数
冒号后有一个空格,按病毒特征码的输入顺序进行输出。 Sample Input3AABBCCooxxCC%dAAAoen….END

/*
hdu 3065 AC自动机(各子串出现的次数)给你m个子串,然后从一个字符串中查找这些子串哪些出现过,出现了多少次
在用ed对子串进行标记。 查询过程中遇到ed则对在相应的子串上 +1hhh-2016-04-23 21:08:09
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
typedef unsigned int ul;
const int maxn = 40010;
const int mod = 10007;
int ans[1005];
int tot;
struct Tire
{
int nex[1000*55][130],fail[1000*55],ed[1000*55];
int root,L;
int newnode()
{
for(int i = 0; i < 130; i++)
nex[L][i] = -1;
ed[L++] = 0;
return L-1;
} void ini()
{
L = 0,root = newnode();
} void inser(char buf[],int id)
{
int len = strlen(buf);
int now = root;
for(int i = 0; i < len; i++)
{
int ta = buf[i];
if(nex[now][ta] == -1)
nex[now][ta] = newnode();
now = nex[now][ta];
}
ed[now] = id;
} void build()
{
queue<int >q;
fail[root] = root;
for(int i = 0; i < 130; i++)
if(nex[root][i] == -1)
nex[root][i] = root;
else
{
fail[nex[root][i]] = root;
q.push(nex[root][i]);
}
while(!q.empty())
{
int now = q.front();
q.pop();
for(int i = 0; i < 130; i++)
{
if(nex[now][i] == -1)
nex[now][i] = nex[fail[now]][i];
else
{
fail[nex[now][i]] = nex[fail[now]][i];
q.push(nex[now][i]);
}
}
}
} void query(char buf[])
{
tot = 0;
int cur = root;
int len = strlen(buf);
for(int i = 0; i < len; i++)
{
cur = nex[cur][(int)buf[i]];
int tp = cur; while(tp != root)
{
if(ed[tp])
ans[ed[tp]]++;
tp = fail[tp];
}
}
}
};Tire ac;
char buf[1005][55];
char to[2000100];
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
ac.ini();
for(int i = 1; i <= n; i++)
{
scanf("%s",buf[i]);
ac.inser(buf[i],i);
}
ac.build();
memset(ans,0,sizeof(ans));
scanf("%s",to);
ac.query(to); for(int i = 1; i <= n; i++)
{
if(ans[i] > 0)
{
printf("%s: %d\n",buf[i],ans[i]);
}
}
}
return 0;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844