$AC$自动机。

用$AC$自动机匹配一次,开一个$flag$记录一下以$i$位置为结尾的最长要打$*$多少个字符,然后倒着扫描一次就可以输出了。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int flag[maxn];
char buf[maxn]; struct Trie
{
int next[maxn][],fail[maxn],end[maxn],Len[maxn];
int root,L;
int newnode()
{
for(int i = ;i < ;i++) next[L][i] = -;
Len[L]= end[L] = ; L++;
return L-;
}
void init()
{
L = ;
root = newnode();
}
void insert(char buf[])
{
int len = strlen(buf);
int now = root;
for(int i = ;i < len;i++)
{
if(next[now][buf[i]-'a'] == -)
next[now][buf[i]-'a'] = newnode();
now = next[now][buf[i]-'a'];
}
end[now]++;
Len[now]=strlen(buf);
}
void build()
{
queue<int>Q;
fail[root] = root;
for(int i = ;i < ;i++)
if(next[root][i] == -)
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 = ;i < ;i++)
if(next[now][i] == -)
next[now][i] = next[fail[now]][i];
else
{
fail[next[now][i]]=next[fail[now]][i];
Q.push(next[now][i]);
}
}
}
void query(char buf[])
{
int len = strlen(buf);
int now = root;
int res = ;
for(int i = ;i < len;i++)
{
int sign;
if(buf[i]>='A'&&buf[i]<='Z') sign=buf[i]-'A';
else if(buf[i]>='a'&&buf[i]<='z') sign=buf[i]-'a';
else { now=root; continue; }
now = next[now][sign];
int temp = now;
while( temp != root )
{
flag[i]=max(flag[i],Len[temp]);
temp = fail[temp];
}
}
}
}; Trie ac; int main()
{
int T,n; scanf("%d",&T);
while( T-- )
{
scanf("%d",&n); ac.init();
for(int i = ;i < n;i++)
{ scanf("%s",buf); ac.insert(buf); }
ac.build(); getchar(); gets(buf); memset(flag,,sizeof flag);
ac.query(buf); int leng=strlen(buf); int num=; for(int i=leng-;i>=;i--)
{
num=max(num,flag[i]);
if(num==) continue;
else buf[i]='*', num--;
}
printf("%s\n",buf);
}
return ;
}

HDU 5880 Family View的更多相关文章

  1. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  2. hdu 5880 AC自动机

    Family View Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)

    题意:按要求输出.第一列是表示第几行.每行仅仅能有16个字节的字母,第二列是16进制的ASCII码.第三列大写和小写转换 思路:纯模拟,注意字母的十六进制是2位 #include <iostre ...

  4. AC自动机及KMP练习

    好久都没敲过KMP和AC自动机了.以前只会敲个kuangbin牌板子套题.现在重新写了自己的板子加深了印象.并且刷了一些题来增加自己的理解. KMP网上教程很多,但我的建议还是先看AC自动机(Trie ...

  5. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

  6. hdu5880 Family View

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5880 题目: Family View Time Limit: 3000/1000 MS (Ja ...

  7. hdu 4967 Handling the Past

    hdu 4967 Handling the Past view code//把时间离散化,维护一个线段(线段l到r的和用sum[l,r]表示),pop的时候就在对应的时间减一,push则相反 //那么 ...

  8. HDU 1495 非常可乐

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=103711#problem/M /*BFS简单题 链接地址: http://acm.hdu ...

  9. 爆零后的感受外加一道强联通分量HDU 4635的题解

    今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...

随机推荐

  1. 关于sscanf函数的各种详细用法

    看书的时候碰到sscanf函数,就上网查了很多资料,并加以自己的整理,希望对大家有所帮助. (因为参考的博客太多太散,就不一一注明,望大神们见谅) sscanf()  :从一个字符串中读进与指定格式相 ...

  2. 对"一维最大子数组和"问题的思考

    对"一维最大子数组和"问题的思考(homework-01) 一维最大子数组和问题,即给定一个数组,在它所有的连续子数组的和中,求最大的那个和.“最大子数组和”是一个很好的IT面试考 ...

  3. IOS7学习之路十(百度地图API环境搭建)

    百度地图官网的API开发教程链接:点击打开链接 我按照他的教程做的总出现"Apple Mach-O linker command failed with exit code 1"的 ...

  4. jQuery 2.0.3 源码分析Sizzle引擎解析原理

    jQuery 2.0.3 源码分析Sizzle引擎 - 解析原理 声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 先来回答博友的提问: 如何解析 div > p + ...

  5. c# datagridview 设置某行不可见解决办法

    [前提]datagridview与数据库绑定,需要单独设置某行或者某个单元格不可见. [问题分析]直接用this.dataGridCiew1.Rows[0].Visible = false;不可行,会 ...

  6. flask tutorial => make a blog :) flask 搭建博客系统从零开始!

    please follow the tutorial from the official site :) http://flask.pocoo.org/docs/ You could download ...

  7. linux 消息队列例子

    /author:DriverMonkey //phone:13410905075 //mail:bookworepeng@Hotmail.com //qq:196568501 #include < ...

  8. Tapestry5.3使用总结

    1.Tapestry框架的加载是通过Filter来完成的,需要在web.xml中加入以下配置: <filter> <filter-name>app</filter-nam ...

  9. Execl导入问题之文本转换

    前些天在基础数据的导入过程中,遇到了这样一个问题:数据明明存在,可是就是不识别!给出的错误提示是:该数据对应的外键不存在! 我找出其中的一条数据,在外键表中查询是存在的!问题出在哪里了呢? 从exec ...

  10. php的curl封装类

    之前一直做爬虫相关的,每次自己去写一系列curl_setopt()函数太繁琐,我于是封装了如下curl请求类. <?php /** * @author freephp * @date 2015- ...