2016 青岛区域赛网络赛1003 HDU 5880 Family View
来源:互联网 发布:网络剧河神百度云资源 编辑:程序博客网 时间:2024/05/21 09:43
ac自动机,匹配到的时候记录位置及长度,最后替换成星号即可。
开始MLE和TLE各一发
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>using namespace std;int buff[1000010];struct Trie{ int next[500010][26],fail[500010],end[500010]; int root,L; int newnode() { for(int i = 0;i < 26;i++) next[L][i] = -1; end[L++] = 0; return L-1; } void init() { L = 0; root = newnode(); } void insert(char buf[],int id) { int len = id; int now = root; for(int i = 0;i < len;i++) { if(next[now][buf[i]-'a'] == -1) next[now][buf[i]-'a'] = newnode(); now = next[now][buf[i]-'a']; } end[now]=id; } void build() { queue<int>Q; fail[root] = root; for(int i = 0;i < 26;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 < 26;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 query(char buf[],int len) { int now = root; int res = 0; for(int i = 0;i < len;i++) { if(buf[i]<'a'||buf[i]>'z') if(buf[i]>='A'&&buf[i]<='Z') now = next[now][buf[i]-'A']; else continue;//now = next[now][26]; else now = next[now][buf[i]-'a']; int temp = now; while(temp != root) { if(end[temp] != -1) { buff[i-end[temp]+1]=max(end[temp],buff[i-end[temp]+1]); } temp = fail[temp]; } } return res; }};char buf[1000010];Trie ac;int main(){ int t,n; while(scanf("%d",&t) != EOF) { while(t--) { memset(buff,0,sizeof(buff)); scanf("%d",&n); ac.init(); for(int i = 1; i <= n; i++) { scanf("%s\n",buf); ac.insert(buf,strlen(buf)); } ac.build(); gets(buf); int len = strlen(buf); ac.query(buf,len); int x=0; for(int i=0;i<len;i++) { if(x<buff[i]) { x=buff[i]; } if(x) { buf[i]='*'; x--; } } puts(buf); } } return 0;}
0 0
- 2016 青岛区域赛网络赛1003 HDU 5880 Family View
- hdu 5880 Family View ac自动机屏蔽文章关键词 2016青岛网赛
- hdu 5548 sort 2016青岛区域赛网络赛 二分+队列优化
- HDU 5879 - Cure【2016 ACM 区域赛青岛赛区网络赛】
- HDU 5883 2016 ICPC青岛网络赛
- Coding Contest-青岛区域赛网络流
- 2016 青岛区域赛小结
- HDU 5988 2016青岛区域赛 (最小费用流)
- HDU 5880 Family View
- hdu 5880 Family View
- HDU 5880 Family View
- 2016青岛网络赛、
- 青岛区域赛总结
- 2016 ACM青岛区域赛题解
- 【2016-青岛赛区网络赛-D】(Tea,hdu 5881)
- hdu 5883 (欧拉路,青岛网络赛)
- HDU 5879 Cure 青岛网络赛
- 2016 ICPC 青岛 网络赛
- session和cookie的使用总结
- LeetCode #201: Bitwise AND of Numbers Range
- c#建造者模式
- [Jsoup]Jsoup Html页面处理简单用法
- 微信測試號申請
- 2016 青岛区域赛网络赛1003 HDU 5880 Family View
- STEAM俱乐部--制作月球灯
- 洛谷月赛 U4728 小L的牛栏
- 右左法则----复杂指针解析(函数指针与数组指针)
- Android实战技巧之四十:Android5.1.1源代码编译与烧写
- 第一次在CSDN写博客,要坚持!
- Verilog语法_2(case语法和task语法)
- Popupwindow的入门
- 18考研:择校必知九大招