【Ac自动机】hdu 5880 Family View
来源:互联网 发布:mfc编程教程 编辑:程序博客网 时间:2024/06/05 11:12
Link:http://acm.split.hdu.edu.cn/showproblem.php?pid=5880
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N = 1000110;int len[N];int res[N];struct Aho{ struct Node{ int nex[26]; int fail,endd; }node[N]; int Size; queue<int> que; int newnode(){ for(int i = 0; i < 26; i++) node[Size].nex[i] = 0; node[Size].fail = node[Size].endd = 0; return Size++; } void init(){ while(que.size()) que.pop(); Size = 0; newnode(); } void Insert(char *s,int id) { int L = len[id]; int now = 0; for(int i = 0; i < L; i++){ int x = s[i]-'a'; if(node[now].nex[x]==0) node[now].nex[x]=newnode(); now = node[now].nex[x]; } node[now].endd = id; } void build() { node[0].fail = 0; for(int i = 0; i < 26; i++) { if(node[0].nex[i]) { node[node[0].nex[i]].fail = 0; que.push(node[0].nex[i]); } } while(que.size()) { int u = que.front(); que.pop(); for(int i = 0; i < 26; i++) { if(node[u].nex[i]==0) node[u].nex[i] = node[node[u].fail].nex[i]; else { node[node[u].nex[i]].fail = node[node[u].fail].nex[i]; que.push(node[u].nex[i]); } } } } int pos[N]; void marth(char *s) { memset(pos,0,sizeof(pos)); int L = strlen(s); int now = 0; for(int i = 0; i < L; i++) { int x; if(s[i] >= 'a' && s[i] <= 'z') x = s[i]-'a'; else if(s[i] >= 'A' && s[i] <= 'Z') x = s[i]-'A'; else continue; now = node[now].nex[x]; int temp = now; while(temp) { if(node[temp].endd) { pos[i+1]-=1; pos[i-len[node[temp].endd]+1]+=1; } temp = node[temp].fail; } } long long cnt=0; for(int i=0;i<L;i++) { cnt+=pos[i]; if(cnt<=0) printf("%c",s[i]); else printf("*"); } puts(""); }}aho;char s[N];int main(){ int T,n; scanf("%d",&T); while(T--) { aho.init(); scanf("%d",&n); for(int i = 1; i <= n; i++){ scanf("%s",s); len[i] = strlen(s); aho.Insert(s,i); } aho.build(); getchar(); gets(s);// printf("%s\n",s); aho.marth(s); } return 0;}
阅读全文
0 0
- 【HDU 5880】Family View(AC自动机)
- HDU 5880 Family View(AC自动机)
- hdu 5880 Family View AC自动机
- HDU 5880 Family View AC自动机
- [HDU 5880] Family View (AC自动机)
- HDU 5880 Family View (AC自动机)
- 【Ac自动机】hdu 5880 Family View
- Hdu 5880 Family View AC自动机 水
- HDU 5880 Family View 好容易MLE的AC自动机 *
- 【HDU5880】Family View(AC自动机)
- hdu 5880 Family View ac自动机屏蔽文章关键词 2016青岛网赛
- 【hdu 5880】 【AC自动机+差分法】Family View 把匹配到的敏感词改成*
- HDU5880 Family View(AC自动机)
- hdu5880 Family View (AC自动机)
- HDU 5880 Family View
- hdu 5880 Family View
- HDU 5880 Family View
- HDU 5880 AC自动机
- java.nio.charset.MalformedInputException: Input length = 2 解决办法
- linux c 实现简易HTTP服务器
- NYOJ 33 蛇形填数
- Fragment生命周期测试
- Appium+python环境搭建
- 【Ac自动机】hdu 5880 Family View
- 还在为画“类Word文档报表”而发愁吗?
- Linux命令之vi/vim
- Android中密码输入内容可见性切换
- MyBatis学习(一) 入门+例子
- js Blob对象介绍
- Struts2初学 struts.xml详解 一
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]:
- 差距(模板题)