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 ...
随机推荐
- Asp.Net MVC 3
Asp.Net MVC 3 wcf基础教程之 契约(合同)Contract 摘要: 在前几篇博客中我有说到服务的寄宿,就是服务要运行起来必须采取的几种方式,相当于我们可以照葫芦画瓜的效果运行一个w ...
- 初试KONCKOUT+WEBAPI简单实现增删改查
初试KONCKOUT+WEBAPI简单实现增删改查 前言 konckout.js本人也是刚刚接触,也是初学,本文的目的是使用ko和asp.net mvc4 webapi来实现一个简单增删改查操作.Kn ...
- linux下安装java
搞了一年IT了,作为IT人没怎么玩过linux挺丢脸的,要好好整整. 先从熟悉的来,在linux下开发java,首先要搭建环境. linux有一个工具yum,非常好用. 1.yum install j ...
- dotTrace 学习笔记
KEYGEN!你懂的(点击下载),仅供学习参考! jetbrains 全系列产品,仅支持最新版本(Ultimate 版本),源码就不提供了,感兴趣的自行反编译一下,未混淆.
- WPF 自定义 MessageBox (相对完善版)
WPF 自定义 MessageBox (相对完善版) 基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...
- MSSQL 清空日志 删除日志文件
MSSQL 清空日志 删除日志文件 最近的项目主要做数据的归档,把数据从一个数据库拉到另一个数据库,照成新数据库的日志文件非常大:于是想把日志文件删除.最简单就是先分离数据库->删除日志文件-& ...
- Sql Server (错误:7302)
windows server 2008 x64 sql server 2008 r2 OraClient 11g 错误提示: 解决办法:
- 创建Sdcard
下载好源码之后编译生成了模拟器,这个时候的模拟器是没有SDcard的.这个时候需要创建需要为虚拟机创建SDcard 我们创建mksdcard 256M <src>/out/target/p ...
- 2016年美国数学建模比赛(MCM/ICM) E题环境科学 Are we heading towards a thirsty planet? 人工精准翻译。
第二次参加建模,觉得建模太有趣了,用几天的时间,迅速学习新知识,并解决实际问题. ——————————————————————————————————————————————————————————— ...
- 简单的遮罩层效果,user登陆显示效果
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...