HDU 3695 Computer Virus on Planet Pandora AC自动机
来源:互联网 发布:linux创建多层目录 编辑:程序博客网 时间:2024/06/01 18:55
题目连接:http://blog.csdn.net/SolarDomo/article/category/6354437
题意:问模式串在主串和主串的逆串中出现多少个
建自动机之后,把正串和反串都跑一边自动机,遍历到的VALUE值的清空
代码:
#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 250000 + 5,sigma_size = 26;int ch[maxn][sigma_size],value[maxn],tot,fail[maxn];void Init_Trie(){ memset(ch[0],0,sizeof ch[0]); value[0] = 0;tot = 1;}void Insert(char *s,int v){ int cur = 0,idx; while(*s){ idx = *s - 'A'; if(!ch[cur][idx]){ memset(ch[tot],0,sizeof ch[tot]); value[tot] = 0; ch[cur][idx] = tot++; }cur = ch[cur][idx]; s++; } value[cur]++;}void GetFail(){ queue<int> Q; Q.push(0);fail[0] = -1; while(!Q.empty()){ int cur = Q.front();Q.pop(); for(int i = 0;i <sigma_size;++i){ if(ch[cur][i]){ int f = fail[cur]; while(f != -1 && ch[f][i] == 0) f = fail[f]; fail[ch[cur][i]] = (f == - 1) ? 0 : ch[f][i]; Q.push(ch[cur][i]); } else{ ch[cur][i] = (cur == 0) ? 0 : ch[fail[cur]][i]; } } }}int Search(char *s){ int cur = 0,ret = 0; while(*s){ int idx = *s - 'A'; cur = ch[cur][idx]; if(value[cur]){ int tmp = cur; while(tmp){ ret += value[tmp];value[tmp] = 0; tmp = fail[tmp]; } } s++; } return ret;}const int maxc = 5100000 + 5;char str[maxc],tmpc;int main(){ int T;sf("%d",&T); while(T--){ Init_Trie(); int n;sf("%d",&n); while(n--){ sf("%s",str); Insert(str,1); }tmpc = getchar(); int len = 0; while(tmpc = getchar()){ if(tmpc == '\n') break; else if(tmpc == '['){ int cnt;sf("%d",&cnt);tmpc = getchar(); while(cnt--){ str[len++] = tmpc; } getchar(); } else{ str[len++] = tmpc; } }str[len] = '\0'; GetFail(); int ret = Search(str); strrev(str);ret += Search(str); pf("%d\n",ret); }}
0 0
- HDU 3695 Computer Virus on Planet Pandora(AC自动机)
- HDU 3695 Computer Virus on Planet Pandora(AC自动机)
- hdu 3695 Computer Virus on Planet Pandora AC自动机
- hdu 3695 Computer Virus on Planet Pandora ac自动机
- HDU 3695 Computer Virus on Planet Pandora (AC自动机)
- HDU 3695 Computer Virus on Planet Pandora AC自动机
- 【AC自动机】HDU 3695 Computer Virus on Planet Pandora 裸题
- hdu 3695 Computer Virus on Planet Pandora(AC自动机)
- HDU 3695 Computer Virus on Planet Pandora (AC自动机)
- HDU - 3695 - Computer Virus on Planet Pandora(AC自动机)
- HDU 3695 Computer Virus on Planet Pandora AC自动机
- HDU - 3695 Computer Virus on Planet Pandora AC自动机+优化
- HDU 3695 Computer Virus on Planet Pandora AC自动机
- HDU 3695:Computer Virus on Planet Pandora(AC自动机裸题,数组实现AC自动机)
- hdoj 3695 Computer Virus on Planet Pandora 【AC自动机】
- hdu 2896病毒侵袭 && hdu 3695 Computer Virus on Planet Pandora AC自动机
- HDU 3695 Computer Virus on Planet Pandora and HDU 2896 病毒侵袭(AC自动机裸题)
- HDU 3695 Computer Virus on Planet Pandora(10年福州 AC自动机)
- Centos下Yum安装PHP5.5,5.6,7.0
- cookie与session学习笔记 -- day01 会话介绍
- 排序算法:希尔排序(更高效的插入法排序)
- HashMap、HashTable有哪些区别
- Rxjava+ReTrofit+okHttp深入浅出-终极封装三(文件上传)
- HDU 3695 Computer Virus on Planet Pandora AC自动机
- ReactiveCocoa之RAC过滤(八)
- 浅拷贝深拷贝
- 留言板
- SPOJ 3943 Nested Dolls
- Rxjava(变换类)--FlatMap2
- Android之QQ聊天气泡对话实现
- lower_bound/upper_bound(STL)
- 从源码上深度剖析View invalidate 、 postInvalidate、requestLayout