HDU 3065 病毒侵袭持续中 ac自动机 统计文本串的单词和其出现的次数。
来源:互联网 发布:软件研发费用预算表 编辑:程序博客网 时间:2024/05/03 19:59
病毒侵袭持续中
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11762 Accepted Submission(s): 4118
Problem Description
小t非常感谢大家帮忙解决了他的上一个问题。然而病毒侵袭持续中。在小t的不懈努力下,他发现了网路中的“万恶之源”。这是一个庞大的病毒网站,他有着好多好多的病毒,但是这个网站包含的病毒很奇怪,这些病毒的特征码很短,而且只包含“英文大写字符”。当然小t好想好想为民除害,但是小t从来不打没有准备的战争。知己知彼,百战不殆,小t首先要做的是知道这个病毒网站特征:包含多少不同的病毒,每种病毒出现了多少次。大家能再帮帮他吗?
Input
第一行,一个整数N(1<=N<=1000),表示病毒特征码的个数。
接下来N行,每行表示一个病毒特征码,特征码字符串长度在1—50之间,并且只包含“英文大写字符”。任意两个病毒特征码,不会完全相同。
在这之后一行,表示“万恶之源”网站源码,源码字符串长度在2000000之内。字符串中字符都是ASCII码可见字符(不包括回车)。
接下来N行,每行表示一个病毒特征码,特征码字符串长度在1—50之间,并且只包含“英文大写字符”。任意两个病毒特征码,不会完全相同。
在这之后一行,表示“万恶之源”网站源码,源码字符串长度在2000000之内。字符串中字符都是ASCII码可见字符(不包括回车)。
Output
按以下格式每行一个,输出每个病毒出现次数。未出现的病毒不需要输出。
病毒特征码: 出现次数
冒号后有一个空格,按病毒特征码的输入顺序进行输出。
病毒特征码: 出现次数
冒号后有一个空格,按病毒特征码的输入顺序进行输出。
Sample Input
3AABBCCooxxCC%dAAAoen....END
Sample Output
AA: 2CC: 1HintHit:题目描述中没有被提及的所有情况都应该进行考虑。比如两个病毒特征码可能有相互包含或者有重叠的特征码段。计数策略也可一定程度上从Sample中推测。
Source
2009 Multi-University Training Contest 16 - Host by NIT
Recommend
lcy | We have carefully selected several similar problems for you: 2243 2825 3247 3341 2296
很水的题,记录一下ID然后开个数组记录一下就行了。
#include <stdio.h>#include <algorithm>#include <iostream>#include <string.h>#include <queue>using namespace std;string str[1005];struct Trie{ int next[210*500][128],fail[210*500],end[210*500]; int root,L; int newnode() { for(int i = 0; i < 128; i++) next[L][i] = -1; end[L++] = 0; return L-1; } void init() { L = 0; root = newnode(); } void insert(string buf,int id) { int len = buf.size(); int now = root; for(int i = 0; i < len; i++) { if(next[now][buf[i]] == -1) next[now][buf[i]] = newnode(); now = next[now][buf[i]]; } end[now]=id; } void build() { queue<int>Q; fail[root] = root; for(int i = 0; i < 128; i++) if(next[root][i] == -1) next[root][i] = root; else { fail[next[root][i]] = root; Q.push(next[root][i]); } while( !Q.empty() ) { int now = Q.front(); Q.pop(); for(int i = 0; i < 128; i++) if(next[now][i] == -1) next[now][i] = next[fail[now]][i]; else { fail[next[now][i]]=next[fail[now]][i]; Q.push(next[now][i]); } } } int vis[1005]; int query(string buf,int n) { int len = buf.size(); int now = root; int res = 0; memset(vis,0,sizeof(vis)); int flag=0; for(int i = 0; i < len; i++) { now = next[now][buf[i]]; int temp = now; while( temp != root ) { if(end[temp]!=0) { vis[end[temp]]++; flag=1; } temp = fail[temp]; } } for(int i=1; i<=n; i++) { if(vis[i]>0) cout<<str[i]<<": "<<vis[i]<<endl; } } void debug() { for(int i = 0; i < L; i++) { printf("id = %3d,fail = %3d,end = %3d,chi = [",i,fail[i],end[i]); for(int j = 0; j < 128; j++) printf("%2d",next[i][j]); printf("]\n"); } }} ac;char s[2000005];int main(){ int n; while(cin>>n) { ac.init(); for(int i=1; i<=n; i++) { cin>>str[i]; ac.insert(str[i],i); } ac.build(); scanf("%s",s); ac.query(s,n); } return 0;}
0 0
- HDU 3065 病毒侵袭持续中 ac自动机 统计文本串的单词和其出现的次数。
- hdu3065 病毒侵袭持续中(AC自动机,统计每个字符串出现的次数)
- HDU 3065 病毒侵袭持续中(AC自动机记录模式串出现次数)
- hdoj 3065 病毒侵袭持续中 【AC自动机 基础题】【输出每个模式串出现的次数】
- HDU 病毒侵袭持续中(AC自动机)
- AC自动机 病毒侵袭持续中 HDU
- HDU 3065 病毒侵袭持续中(AC自动机)
- hdu 3065 病毒侵袭持续中 //AC自动机
- HDU 3065:病毒侵袭持续中(AC自动机)
- HDU 3065 病毒侵袭持续中 AC自动机
- hdu 3065 病毒侵袭持续中 AC自动机模版题
- hdu 3065 病毒侵袭持续中 - AC自动机
- HDU 3065 病毒侵袭持续中(AC自动机模板)
- [HDU 3065]病毒侵袭持续中[AC自动机][模板题]
- hdu 3065 病毒侵袭持续中(AC自动机)
- hdu 3065 病毒侵袭持续中(AC自动机)
- hdu 3065 病毒侵袭持续中 (AC自动机)
- HDU 3065 AC 自动机再来。。 病毒持续侵袭中
- HTML5学习_day12(1)--html布局
- FCC Basic Algorithm Scripting 基础算法集
- Linux - chown chgrp
- 计算机图形学基础(第二版)陆枫 何云峰(1)
- 3-06 Linux内核子系统
- HDU 3065 病毒侵袭持续中 ac自动机 统计文本串的单词和其出现的次数。
- 关于spring+mybatis多数据源,报Invalid bound statement的问题
- 面向对象_类与类,类与接口,接口与接口的关系
- UIWebView注入js代码来改变其背景颜色和尺寸大小
- RecyclerView的分割线:ItemDecoration
- 结构体指针
- Atomikos
- 原生javascript的动态效果demo
- 代码整洁之道总结(二)