HDU 5880 Family View
$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的更多相关文章
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- hdu 5880 AC自动机
Family View Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU - 4054 Hexadecimal View (2011 Asia Dalian Regional Contest)
题意:按要求输出.第一列是表示第几行.每行仅仅能有16个字节的字母,第二列是16进制的ASCII码.第三列大写和小写转换 思路:纯模拟,注意字母的十六进制是2位 #include <iostre ...
- AC自动机及KMP练习
好久都没敲过KMP和AC自动机了.以前只会敲个kuangbin牌板子套题.现在重新写了自己的板子加深了印象.并且刷了一些题来增加自己的理解. KMP网上教程很多,但我的建议还是先看AC自动机(Trie ...
- 2016 年青岛网络赛---Family View(AC自动机)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...
- hdu5880 Family View
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5880 题目: Family View Time Limit: 3000/1000 MS (Ja ...
- hdu 4967 Handling the Past
hdu 4967 Handling the Past view code//把时间离散化,维护一个线段(线段l到r的和用sum[l,r]表示),pop的时候就在对应的时间减一,push则相反 //那么 ...
- HDU 1495 非常可乐
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=103711#problem/M /*BFS简单题 链接地址: http://acm.hdu ...
- 爆零后的感受外加一道强联通分量HDU 4635的题解
今天又爆零了,又是又,怎么又是又,爆零爆多了,又也就经常挂嘴边了,看到这句话,你一定很想说一句””,弱菜被骂傻,也很正常啦. 如果你不开心,可以考虑往下看. 翻到E(HDU 4635 Strongly ...
随机推荐
- Pi
Math]Pi 数学知识忘地太快,在博客记录一下pi的生成. 100 Decimal places 3.1415926535897932384626433832795028841971693993 ...
- C/C++基础知识总结——数据的共享与保护
1. 标识符的作用域与可见性 1.1 作用域 标识符的作用域包括:函数原型作用域.局部作用域.类作用域.命名空间作用域 (1) 函数原型作用域:函数的参与的作用域就是从函数的开始到结束 (2) 局部作 ...
- Controller的激活
Controller的激活 概述 在此系列开篇的时候介绍了MVC的生命周期 , 对于请求的处理,都是将相应的类的方法注册到HttpApplication事件中,通过事件的依次执行从而完成对请求的处理. ...
- C#获取友好时间差
/// <summary> /// 获取时间差 /// </summary> /// <param name="dtOld">要减的时间< ...
- MVC常见的控制器,接口,数据层之间的操作
user_books_info 类 namespace CiWong.LearningLevel.Mapping { public class user_books_info { /// <su ...
- Event处理
Event处理 今天抽时间写了一部分Event处理方面的函数愈发的觉得jQuery的优秀,自己前期的想法太粗糙,造成后面这些函数参数很多,操作很很不直观,看样子是要重构的节奏,还好小伙儿伴们安慰,架构 ...
- TaskTracker执行map或reduce任务的过程2
TaskTracker执行map或reduce任务的过程(二) 上次说到,当MapLauncher或ReduceLancher(用于执行任务的线程,它们扩展自TaskLauncher),从它们所维护的 ...
- 在网络通讯中应用Protobuf
在网络通讯中应用Protobuf Protobuf的设计非常适用于在网络通讯中的数据载体,它序列化出来的数据量少再加上以K-V的方式来存储数据,对消息的版本兼容性非常强:还有一个比较大的优点就是有着很 ...
- SOA体系结构基础培训教程
SOA体系结构基础培训教程-规范标准篇 引子:本文是<SOA体系结构基础培训教程>第3章<SOA标准与规范>课件,版权所有,转载请注明出处. 随着SOA在业界的应用日益广泛,S ...
- Java笔记:String类
1.String类是不可变类,一旦一个String对象被创建以后,包含在这个对象中的字符序列式不可改变的,直至这个对象被销毁. String s1 = "java"; s1 = s ...