HDU 3065 病毒侵袭持续中 AC自动机
来源:互联网 发布:c语言windows驱动编程 编辑:程序博客网 时间:2024/06/06 16:41
这到底是怎样的一道题?输入里面就没要求要有文件结束符,尼玛,不加文件结束符不让过,靠,真坑。。。。这道题也是考察AC自动机的,AC自动机明白了就会做了,不多说。。。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;struct node{int next[50*1010][128],fail[50*1010],vis[50*1010];int sz,root;int flag[1010];int newnode() {memset(next[sz],0,sizeof(next[sz]));vis[sz++]=0;return sz-1;}void init() {sz=0;root=newnode();memset(flag,0,sizeof(flag));}void insert(char s[],int id) {int i,te=root;for(i=0; s[i]; i++) {if(next[te][s[i]]==0) {int p = newnode();next[te][s[i]] = p;te=p;}else te = next[te][s[i]];}vis[te] = id;}void build_ac_automation() {fail[root] = root;int i;queue<int> que;for(i=0; i<128; i++) {if(next[root][i]==0) {next[root][i] = root;}else {fail[next[root][i]] = root;que.push(next[root][i]);}}while(!que.empty()) {int te=que.front();que.pop();for(i=0; i<128; i++) {if(next[te][i]==0) next[te][i] = next[fail[te]][i];else {fail[next[te][i]] = next[fail[te]][i];que.push(next[te][i]);}}}}void query(char s[]) {int te=root,i;for(i=0; s[i]; i++) {te = next[te][s[i]];int p = te;while(p!=root) {if(vis[p]) {flag[vis[p]]++;}p = fail[p];}}}}; node ac;char s[1005][100],str[2000010];int main() {int n,i;while(scanf("%d",&n)!=EOF) {//getchar();ac.init();for(i=1; i<=n; i++) {scanf("%s",s[i]);ac.insert(s[i],i);}ac.build_ac_automation();scanf("%s",str);//cout<<str<<endl;ac.query(str);//cout<<str<<endl;for(i=1; i<=n; i++) {if(ac.flag[i]) printf("%s: %d\n",s[i],ac.flag[i]);} }return 0;}
0 0
- 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 自动机再来。。 病毒持续侵袭中
- HDU 3065 病毒侵袭持续中(AC自动机)
- hdu 3065 病毒侵袭持续中(AC自动机)
- [hdu 3065] 病毒侵袭持续中(AC自动机)
- hdu 3065 病毒侵袭持续中 ac自动机
- 求得1-100里9出现的次数的c代码
- LeetCode Majority Element
- strcpy()、memcpy()、memmove()、memset()的实现
- 找出两个结点的第一个公共祖先(算法)
- 说说今天(3月12)面试题
- HDU 3065 病毒侵袭持续中 AC自动机
- 今日小结
- 自定义seekbar中,thumb被覆盖掉一部分问题——thumbOffset属性设置
- Codeforces Round #248 (Div. 1)C(AC自动机+DP)
- 关于C#多线程的学习和一点疑惑
- Sqlserver2000连接Oracle11G数据库进行数据实时同步
- wordpress主题(2)日志内容
- 同步内核缓冲区
- 关于Ubuntu菜单项中的%U参数