Description

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty 
of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest 
issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his 
cows not see (clearly, the magazine is in need of better editorial oversight).
FJ has taken all of the text from the magazine to create the string S of length at most 10^5 characters. 
He has a list of censored words t_1 ... t_N that he wishes to delete from S. To do so Farmer John finds 
the earliest occurrence of a censored word in S (having the earliest start index) and removes that instance 
of the word from S. He then repeats the process again, deleting the earliest occurrence of a censored word 
from S, repeating until there are no more occurrences of censored words in S. Note that the deletion of one 
censored word might create a new occurrence of a censored word that didn't exist before.
Farmer John notes that the censored words have the property that no censored word appears as a substring of 
another censored word. In particular this means the censored word with earliest index in S is uniquely 
defined.Please help FJ determine the final contents of S after censoring is complete.
FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S。他有一个包含n个单词的列表,列表里的n个单词
记为t_1...t_N。他希望从S中删除这些单词。 
FJ每次在S中找到最早出现的列表中的单词(最早出现指该单词的开始位置最小),然后从S中删除这个单词。他重复这个操作直到S中
没有列表里的单词为止。注意删除一个单词后可能会导致S中出现另一个列表中的单词 
FJ注意到列表中的单词不会出现一个单词是另一个单词子串的情况,这意味着每个列表中的单词在S中出现的开始位置是互不相同的 
请帮助FJ完成这些操作并输出最后的S

Input

The first line will contain S. The second line will contain N, the number of censored words. The next N lines contain the strings t_1 ... t_N. Each string will contain lower-case alphabet characters (in the range a..z), and the combined lengths of all these strings will be at most 10^5.
第一行包含一个字符串S 
第二行包含一个整数N 
接下来的N行,每行包含一个字符串,第i行的字符串是t_i

Output

The string S after all deletions are complete. It is guaranteed that S will not become empty during the deletion process.
一行,输出操作后的S
 

Sample Input

begintheescapexecutionatthebreakofdawn
2
escape
execution

Sample Output

beginthatthebreakofdawn
/*
AC自动机
和bzoj3942差不多的做法,只不过变成了多串,需要在自动机上匹配的时候,
记录上一次匹配的位置,然后在这个位置上继续匹配,碰到完整的单词就做删减。
*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#define N 100010
using namespace std;
int a[N][],point[N],danger[N],le[N],pos[N],sta[N],n,m,size=;
char ch[N],s[N];
queue<int> q;
void insert(){
int len=strlen(s),now=;
for(int i=;i<len;i++){
int t=s[i]-'a';
if(!a[now][t]) a[now][t]=++size;
now=a[now][t];
}
danger[now]=;le[now]=len;
}
void build(){
q.push();point[]=;
while(!q.empty()){
int now=q.front();q.pop();
for(int i=;i<;i++){
if(!a[now][i]){
a[now][i]=a[point[now]][i];
continue;
}
int k=point[now];
while(!a[k][i]) k=point[k];
point[a[now][i]]=a[k][i];
danger[a[now][i]]|=danger[a[k][i]];
q.push(a[now][i]);
}
}
}
void solve(){
int len=strlen(ch),top=;pos[]=;
for(int i=;i<len;i++){
int t=ch[i]-'a',k=pos[sta[top]];
sta[++top]=i;
while(!a[k][t]) k=point[k];
pos[i]=a[k][t];
if(danger[a[k][t]]) top-=le[a[k][t]];
}
for(int i=;i<=top;i++) printf("%c",ch[sta[i]]);
}
int main(){
scanf("%s%d",ch,&n);
for(int i=;i<;i++) a[][i]=;
for(int i=;i<=n;i++){
scanf("%s",s);
insert();
}
build();solve();
return ;
}

Censoring(bzoj 3940)的更多相关文章

  1. [Usaco2015 Feb]Censoring(bzoj 3942)

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  2. [BZOJ3940]:[Usaco2015 Feb]Censoring(AC自动机)

    题目传送门 题目描述: FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过105的字符串S.他有一个包含n个单词的列表,列表里的n个单词记为t1…tN.他希望从S中删除这些单词.FJ每次在S中 ...

  3. 晨跑(bzoj 1877)

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...

  4. 洛谷 P3159(BZOJ 2668)[CQOI2012]交换棋子

    有一个\(n\)行\(m\)列的黑白棋盘,你每次可以交换两个相邻格子(相邻是指有公共边或公共顶点)中的棋子,最终达到目标状态.要求第\(i\)行第\(j\)列的格子只能参与\(m[i][j]\)次交换 ...

  5. 洛谷P1198 [JSOI2008]最大数(BZOJ.1012 )

    To 洛谷.1198 最大数 题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当 ...

  6. SHOI 2007 仙人掌图(BZOJ 1023)

    1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2564  Solved: 1062 Descrip ...

  7. 飞镖(bzoj 2335)

    Description 飞镖是在欧洲颇为流行的一项运动.它的镖盘上分为20个扇形区域,分别标有1到20的分值,每个区域中有单倍.双倍和三倍的区域,打中对应的区域会得到分值乘以倍数所对应的分数.例如打中 ...

  8. 海拔(bzoj 2007)

    Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个 正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1) ...

  9. 分裂游戏(bzoj 1188)

    Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏. 该游戏的规则试: 共有 n 个瓶子, 标号为 0,1,2.....n-1, 第 i 个瓶子中装有 p[i]颗巧克力豆,两个人轮流取豆子 ...

随机推荐

  1. JDK的安装以及环境变量的配置

    一.JDK的安装 1.百度搜索jdk1.8 2.进入网页选择Downloads 3. 选择电脑的版本(x86 32位 x64 64位) 4.下载好后,直接双击即可,一直下一步即可完成安装 二.环境变量 ...

  2. JWT的使用流程

    JWT的实现原理 一篇文章告诉你JWT的实现原理 发布于 3 个月前 作者 axetroy 3097 次浏览 来自 分享 在使用 JWT 的时候,有没有想过,为什么我们需要 JWT?以及它的工作原理是 ...

  3. PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序

    PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...

  4. python3 简单服务器监控,自动发送邮件

    import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimpo ...

  5. Linux中断体系结构

    1.中断处理体系结构 Linux内核将所有中断统一编号,使用一个irq_desc结构数组来描述这些中断. 数组声明在/linux/kernel/irq/handle.c中,其中#define NR_I ...

  6. 关于stm32优先级大小的理解

    转载自:https://www.cnblogs.com/ZKeJun/p/6112591.html 一. 组别:0>1>2>3>4   组别优先顺序(第0组优先级最强,第4组优 ...

  7. zigbee 中 OSAL 事件传递机制和消息传递机制

    一.概述 OSAL (Operating System Abstraction Layer) ,翻译为"操作系统抽象层". OSAL 就是一种支持多任务运行的系统资源分配机制.OS ...

  8. Linux学习-登录档的轮替(logrotate)

    rsyslogd 利用的是 daemon 的方式来启动的, 当有需求的时候立刻就会被执行的,但是 logrotate 却是在规定的时间到了之后才来进行登录档的轮 替, 所以这个 logrotate 程 ...

  9. MediaStore类的使用

    安卓系统会在每次开机之后扫描所有文件并分类整理存入数据库,记录在MediaStore这个类里,通过这个类就可以快速的获得相应类型的文件. 当然这个类只是给你一个uri,提取文件的操作还是要通过Curo ...

  10. 哪里是Maven的中央存储库?

    当你建立了一个Maven工程,Maven会检查你的pom.xml文件,确定要下载的依赖.首先,Maven将从您的本地库Maven查找,如果没有找到,Maven会从中央存储库-http://repo1. ...