CENSORING
CENSORING
题目描述
FJ为它的奶牛订阅了很多杂志,balabala.......,其中有一些奶牛不宜的东西(比如如何煮牛排)。
FJ将杂志中所有的文章提取出来组成一个长度最多为10^5的字符串S。他有一个要从S中删除的词语的列表,t1,t2...tn。
FJ每次找到最早的出现在列表里的子串,然后将其删去。他重复此过程,直到找不到这样的子串。值得注意的是删除一个单词可能产生一个新的之前并没有出现过的要被删除的单词。
FJ保证列表中没有一个字符串是另一个字符串的子串。要就是说每次要删的单词是唯一确定的。
帮助FJ确定最终S的删减版。
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 300050
using namespace std;
int n,len,tot,top;
int tr[maxn][],fail[maxn],p[maxn];
char s[maxn],ch[maxn];
int zh[maxn];char ans[maxn];
void ins(){
int len=strlen(ch),k=;
for(int i=;i<len;i++){
if(!tr[k][ch[i]-'a'])tr[k][ch[i]-'a']=++tot;
k=tr[k][ch[i]-'a'];
}
p[k]=len;
}
void build(){
queue<int>q;
for(int i=;i<;i++)if(tr[][i])q.push(tr[][i]);
while(!q.empty()){
int k=q.front();q.pop();
for(int i=;i<;i++){
if(tr[k][i]){
fail[tr[k][i]]=tr[fail[k]][i];
q.push(tr[k][i]);
}
else tr[k][i]=tr[fail[k]][i];
}
}
}
int main()
{
scanf("%s",s);
cin>>n;
for(int i=;i<=n;i++){
scanf("%s",ch);
ins();
}
build();
n=strlen(s);int k=;
for(int i=;i<n;i++){
k=tr[k][s[i]-'a'];
zh[++top]=k;ans[top]=s[i];
if(p[k]){
top-=p[k];k=zh[top];
}
}
for(int i=;i<=top;i++)printf("%c",ans[i]);
return ;
}
CENSORING的更多相关文章
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 3942: [Usaco2015 Feb]Censoring [KMP]
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 375 Solved: 206[Subm ...
- [Usaco2015 Feb]Censoring(bzoj 3942)
Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...
- bzoj3940: [Usaco2015 Feb]Censoring
AC自动机.为什么洛谷水题赛会出现这种题然而并不会那么题意就不说啦 .终于会写AC自动机判断是否是子串啦...用到kmp的就可以用AC自动机水过去啦 #include<cstdio> #i ...
- 【USACO15FEB】审查(黄金)Censoring (Gold)
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- BZOJ 3940--[Usaco2015 Feb]Censoring(AC自动机)
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 723 Solved: 360[Subm ...
- P4824 [USACO15FEB]Censoring (Silver) 审查(银)&&P3121 [USACO15FEB]审查(黄金)Censoring (Gold)
P3121 [USACO15FEB]审查(黄金)Censoring (Gold) (银的正解是KMP) AC自动机+栈 多字符串匹配--->AC自动机 删除单词的特性--->栈 所以我们先 ...
- BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP
Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...
- 3942: [Usaco2015 Feb]Censoring
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MB Submit: 964 Solved: 480 [Subm ...
- [Usaco2015 Feb]Censoring --- AC自动机 + 栈
bzoj 3940 Censoring 题目描述 FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S. 他有一个包含n个单词的列表,列表里的n个单词记为T1......Tn. ...
随机推荐
- 堆数据结构(heapq)简单应用
## 堆数据结构(heapq)简单应用 # 堆数据结构 heapq # 常用方法:nlargest(),nsmallest(),heapify(),heappop() # 如果需要的个数较小,使用nl ...
- php xml转数组 自定义xml_to_array
<?php header("Content-type: text/xml; charset=utf-8"); $con = file_get_contents('xml路径' ...
- Ubuntu 16.04 swoole扩展安装注意!!!
前言:目前很多项目估计常常会用到swoole扩展,如个人使用Ubuntu虚拟机安装扩展,这里总结一下遇到的问题: 一.先保证服务器时间同步当前地区时间,如北京时间: 1.设定时区 如:设定时区:dpk ...
- MetInfo最新网站漏洞如何修复以及网站安全防护
metinfo漏洞于2018年10月20号被爆出存在sql注入漏洞,可以直接拿到网站管理员的权限,网站漏洞影响范围较广,包括目前最新的metinfo版本都会受到该漏洞的攻击,该metinfo漏洞产生的 ...
- Linux命令备忘录:quota显示磁盘已使用的空间与限制
quota命令用于显示用户或者工作组的磁盘配额信息.输出信息包括磁盘使用和配额限制. 语法 quota(选项)(参数) 选项 -g:列出群组的磁盘空间限制: -q:简明列表,只列出超过限制的部分: - ...
- socket编程基础1——hostent、in_addr、gethostbyname、inet_ntoa
1. struct hostent结构体 struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; ...
- 分支push不上去的问题
还原一下现场,我在自己的项目里面,从master里面checkout的一个分支,当我在我这个分支里面进行 push代码的操作,我突然发现我的代码不能执行push的操作,如图 这个原因是由于远端的仓库没 ...
- LeetCode:17. Letter Combinations of a Phone Number(Medium)
1. 原题链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ 2. 题目要求 给定一 ...
- 活动的生命周期 Android
1.运行程序 onCreate().onStart()和 onResume() 2.跳转到非弹框视图控制器 onPause()和 onStop() 返回上一个视图控制器(没被回收) onRestart ...
- c++ list_iterator demo
#include <iostream> #include <list> using namespace std; typedef list<int> Integer ...