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 ...
随机推荐
- [转]Libev教程
libev Table of Contents 1 libev 1.1 About The Code 1.2 EventLoop 1.3 Watcher 1.4 How it works 1.4.1 ...
- MvcMovieStore mvc5.0,EF6.01
MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 4.创建数据上下文和数据实体模型 说明:MvcMovieStore项目已经发布上线,想了解最新版本功能请登 ...
- [转]JavaScriptCore by Example
原文:http://www.bignerdranch.com/blog/javascriptcore-example/ JavaScriptCore is not a new framework; i ...
- 对linux高级用户有用的20个命令
41.命令:ifconfig ifconfig命令用于配置网络接口信息.如配置网络接口的ip地址,默认网关地址等,以便机器能够联通互联网. 显示当前网络接口信息 viidiot@ubuntu:~$ i ...
- 5个Unix命令
5个Unix命令 原文: http://spin.atomicobject.com/2013/09/09/5-unix-commands/ 希望早几年知道的5个Unix命令 使用*nix系统已经有一段 ...
- ThreadPool&ManualResetEvent
在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 这一般使用ThreadPool(线程池)来解决: 另一种情况:线程 ...
- java.lang.NoClassDefFoundError: com.umeng.analytics.MobclickAgent
07-24 09:58:23.239: E/AndroidRuntime(29487): FATAL EXCEPTION: main 07-24 09:58:23.239: E/AndroidRunt ...
- 关于default的位置问题:default放在前面
在linux内核的文件系统中,有这样的一段代码: 473 if (this.name[0] == '.') switch (this.len) { 474 default: 475 break; 47 ...
- ZOJ 3529 A Game Between Alice and Bob 博弈好题
A Game Between Alice and Bob Time Limit: 5 Seconds Memory Limit: 262144 KB Alice and Bob play t ...
- 设计模式08---设计模式之抽象工厂模式(Abstract Factory)
1.场景模拟 举个生活中常见的例子:组装电脑,我们在组装电脑的时候,通常要选择一系列的配件,比如选择CPU时候,需要注意品牌,型号,针脚数目,主频,只有这些都确定下来,才能确定一个CPU.同样,主板也 ...