【bzoj3940】[Usaco2015 Feb]Censoring
【题目描述】
2
escape
execution
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 100010
int n,cnt,top,end[MAXN],fail[MAXN],deep[MAXN],f[MAXN],q[MAXN],stack[MAXN],tr[MAXN][];
char b[MAXN],ch[MAXN];
void insert()
{
int now=,len=strlen(ch+);
for(int i=;i<=len;i++)
{
if(!tr[now][ch[i]-'a']) tr[now][ch[i]-'a']=++cnt;
now=tr[now][ch[i]-'a'];
}
end[now]=max(end[now],len);
}
void build()
{
int head=,tail=;
for(int i=;i<;i++) if(tr[][i]) q[++tail]=tr[][i];
while(++head<=tail)
{
int x=q[head];
for(int i=;i<;i++)
{
if(!tr[x][i]) tr[x][i]=tr[fail[x]][i];
else {fail[tr[x][i]]=tr[fail[x]][i]; q[++tail]=tr[x][i];}
}
}
}
void find()
{
int len=strlen(b+);
for(int i=,x=;i<=len;i++)
{
f[i]=tr[f[stack[top]]][b[i]-'a'];
stack[++top]=i;
top-=end[f[i]];
}
}
int main()
{
//freopen("cin.in","r",stdin);
//freopen("cout.out","w",stdout);
scanf("%s%d",b+,&n);
for(int i=;i<=n;i++) {scanf("%s",ch+); insert();}
build();
find();
for(int i=;i<=top;i++) printf("%c",b[stack[i]]);
return ;
}
【bzoj3940】[Usaco2015 Feb]Censoring的更多相关文章
- 【BZOJ3940】[USACO2015 Feb] Censoring (AC自动机的小应用)
点此看题面 大致题意: 给你一个文本串和\(N\)个模式串,要你将每一个模式串从文本串中删去.(此题是[BZOJ3942][Usaco2015 Feb]Censoring的升级版) \(AC\)自动机 ...
- 【bzoj3940】[Usaco2015 Feb]Censoring AC自动机
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 【bzoj3942】[Usaco2015 Feb]Censoring
[题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程. [样例输入] whatth ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最大生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【KMP】BZOJ3942-[Usaco2015 Feb] Censoring
[题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程.输出最后的S串. [思路]三 ...
- 【bzoj3943】[Usaco2015 Feb]SuperBull
题目描述 Bessie and her friends are playing hoofball in the annual Superbull championship, and Farmer Jo ...
随机推荐
- 【MFC】断言(ASSERT)的用法
摘自:Moondark http://www.cnblogs.com/moondark/archive/2012/03/12/2392315.html 断言(ASSERT)的用法 我一直以为as ...
- 剑指offer-第五章优化时间和空间效率(从1到n的整数中1出现的次数)
题目:输入一个整数n,从1到n这n个十进制整数中1出现的次数. 思路1:对1到n中的任意一个数i对其进行求余数来判断个位是否为1,然后再求除数,判断十位是否为1.统计出1的个数.然后对1到n用一个循环 ...
- 通信对象System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。
问题描述:在客户端站点访问WCF服务后,在页面停留时间过长,客户端站点将会报错.报错内容如下: 通信对象System.ServiceModel.Channels.ServiceChannel 无法用于 ...
- Spring IOC容器在Web容器中是怎样启动的
前言 我们一般都知道怎样使用spring来开发web应用后,但对spring的内部实现机制通常不是很明白.这里从源码角度分析下Spring是怎样启动的.在讲spring启动之前,我们先来看看一个web ...
- 使用DeflateStream压缩与解压
具体可以了解下:http://msdn.microsoft.com/zh-cn/library/system.io.compression.deflatestream(v=vs.110).aspx / ...
- Python 函数 set()
set() 功能: set() 函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集.差集.并集等. iterable -- 可迭代对象对象:返回新的集合对象. 语法 ...
- javabrideg的使用实践
(1)进入这个网站http://sourceforge.net/projects/php-java-bridge/files,选择Binary package,然后选择最新的版本Php-java-br ...
- (转)Android中的基类—抽取出来公共的方法
在Android中,一般来说一个应用会存在几十个页面,并且一个应用一般也会使用一个特定的主题,其中的页面的风格也是一致的,并且页面中的动画效果.页面的切换效果等也应该保持同样的风格,那么就需要一个基类 ...
- 让Delphi XE5跟其他版本的Delphi共存
找到Delphi XE5的安装根目录 .... \Program Files (x86)\Embarcadero\RAD Studio\12.0\bin下的cglm.ini文件, 打开cglm.i ...
- Regex正则表达式
正则表达式 热身 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将匹配的子串做替换或者从某个串中取出符合某个条件的子串等. 例如 g ...