BZOJ-3940:Censoring(AC自动机裸题)
Input
Output
Sample Inputbegintheescapexecutionatthebreakofdawn 2 escape execution
Sample Outputbeginthatthebreakofdawn
题意:给N个字符串,设集合为T,以及一个长字符串S,对于S,一直删第一个字串,如果其存在T集合里,则删去,问删到最后S为?
思路:N个字符串建立AC自动机,然后S在自动机上面跑,如果跑到的位置是“关键点”,则删去,同时跑的位置跑到删去后AC自动机对应的位置。
所以记录当前串和每个长度对应的位置即可。(送分题
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
char c[maxn],s[maxn],ans[maxn];
int ch[maxn][],End[maxn],fail[maxn],q[maxn];
int pos[maxn],dep[maxn],head,tail,cnt;
void insert()
{
int Now=,d=; for(int i=;c[i];i++){
d++;
if(!ch[Now][c[i]-'a']) ch[Now][c[i]-'a']=++cnt,dep[cnt]=d;
Now=ch[Now][c[i]-'a'];
} End[Now]=;
}
void failbuild()
{
for(int i=;i<;i++) if(ch[][i]) q[++head]=ch[][i];
while(tail<head){
int Now=q[++tail];
for(int i=;i<;i++){
if(ch[Now][i]) {
fail[ch[Now][i]]=ch[fail[Now]][i];
q[++head]=ch[Now][i];
}
else ch[Now][i]=ch[fail[Now]][i];
}
}
}
int main()
{
int N,L,i,j;
scanf("%s%d",s+,&N);
for(i=;i<=N;i++){
scanf("%s",c+);
insert();
}
failbuild();
int top=,Now=;
for(i=;s[i];i++){
ans[++top]=s[i];
Now=ch[Now][s[i]-'a'];
pos[top]=Now;
if(End[Now]){
top-=dep[Now]; Now=pos[top];
}
}
for(i=;i<=top;i++) printf("%c",ans[i]);
return ;
}
BZOJ-3940:Censoring(AC自动机裸题)的更多相关文章
- AC自动机裸题
HDU 2222 Keywords Search 模板题.对模式串建立AC自动机然后在trie树上找一遍目标串即可. # include <cstdio> # include <cs ...
- HDU 2222 AC自动机 裸题
题意: 问母串中出现多少个模式串 注意ac自动机的节点总数 #include <stdio.h> #include <string.h> #include <queue& ...
- HDU 3065 AC自动机 裸题
中文题题意不再赘述 注意 失配数组 f 初始化一步到位 #include <stdio.h> #include <string.h> #include <queue&g ...
- HDU 2896 AC自动机 裸题
中文题题意不再赘述 注意字符范围是可见字符,从32开始到95 char c - 32 #include <stdio.h> #include <string.h> #inclu ...
- [Usaco2015 Feb]Censoring --- AC自动机 + 栈
bzoj 3940 Censoring 题目描述 FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S. 他有一个包含n个单词的列表,列表里的n个单词记为T1......Tn. ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- HDU 3065 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...
- HDU 2896 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...
- HDU 2222(AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...
随机推荐
- Python中strip方法的妙用
[开胃小菜] 当提到python中strip方法,想必凡接触过python的同行都知道它主要用来切除空格.有下面两种方法来实现. 方法一:用内置函数 #<python> if __name ...
- Little-endian和Big-endian模式
这段C程序的结果是多少? 嵌入式系统开发者应该对Little-endian和Big-endian模式非常了解.采用Little-endian模式的CPU对操作数的存放方式是从低字节到高字节,而Big- ...
- JS基础知识再整理..........不断更新中
1.JS的五种基本数据类型:字符串.数值.布尔.null.underfined. 2.在JS中,字符串.数值.布尔三种数据类型,有其属性和方法: 3.字符串的三种常用方法[.indexof()..su ...
- 【BZOJ4520】[Cqoi2016]K远点对 kd-tree+堆
[BZOJ4520][Cqoi2016]K远点对 Description 已知平面内 N 个点的坐标,求欧氏距离下的第 K 远点对. Input 输入文件第一行为用空格隔开的两个整数 N, K.接下来 ...
- function declarations are hoisted and class declarations are not 变量提升
Classes - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes ...
- 点聚-weboffice 6.0 (二)
1.修订操作 //设置当前操作用户 function SetUserName() { try{ var webObj=document.getElementById("WebOffice1& ...
- testng testcase失败重试
简单介绍 需求场景:测试移动端应用,常会因为点击失效.网络延迟大等原因导致测试脚本失败.这时,需要自动重新运行失败的脚本,直到脚本成功通过或者到达限定重试次数. 解决方案:实现testng的IRetr ...
- 用fiddler替换线上网页资源调试界面
fiddler 是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有进出fiddler的数据(指cookie,html,js,css等文件,这些都 ...
- mongo简介
MongoDB MongoDB是一款强大.灵活.且易于扩展的通用型数据库 MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服 ...
- 【转】Unicode(UTF-8, UTF-16)令人混淆的概念
参考地址:http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html Java中,char类型用UTF-16编码描述一个代码单元 为啥 ...