【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 ...
随机推荐
- ng 变量和常量服务
<!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <met ...
- 从无到有开发自己的Wordpress博客主题---局部模板的准备
毫无疑问,我们媒体页面都会有header和footer,这些用到的内容几乎是一样的. 从无到有,我们先不考虑后面可能用到的Search和Comment等的模板,后面的我会在文本最后面追加. 开始之前, ...
- c++ wchar_t 与char 直接的转换【转】
http://blog.163.com/tianshi_17th/blog/static/4856418920085209414977/ 实现了一下 #include "stdafx.h&q ...
- 21天学通C++_Day1
被阿里实习生的第一轮电话面试刷掉以后,幡然醒悟,发现以前学习的C++基础一点都不扎实.为了把基础打扎实,重新学习一遍:为了让自己不放弃,也顺便可以把当天学到的东西记录下来,开始了写博客. 学习书籍:& ...
- PTA L3-020 至多删三个字符 (序列dp/序列自动机)
给定一个全部由小写英文字母组成的字符串,允许你至多删掉其中 3 个字符,结果可能有多少种不同的字符串? 输入格式: 输入在一行中给出全部由小写英文字母组成的.长度在区间 [4, 1] 内的字符串. 输 ...
- python函数返回值
2016-08-09 15:01:38 python函数返回值使用return语句,可以返回任意类型的数.如果return语句执行,它之后的所有语句都不再执行. def func(x,y): pri ...
- 8 函数类型——《Swift3.0从入门到出家
Swift语言中每一个函数都有它特定的数据类型,称其为函数类型 函数类型和基本数据类型一样,可以定义变量或者常量,可以定义函数形参,也可以做为函数的返回值类型 函数类型的格式为:参数列表的数据类型—& ...
- poj 3046 Ant Counting——多重集合的背包
题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ...
- Linux LED字符设备驱动
// 申请IO资源 int gpio_request(unsigned gpio, const char *label); // 释放IO资源 void gpio_free(unsigned gpio ...
- android生命周期参考
public class ActivityDemo extends Activity { private static final String TAG = "ActivityDemo&qu ...