关键词:
3940: [Usaco2015 Feb]Censoring
Time Limit: 10 Sec Memory Limit: 128 MBDescription
Input
Output
Sample Input
2
escape
execution
Sample Output
HINT
Source
#include<map> #include<cmath> #include<queue> #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define ll long long #define N 100010 char s[N],s1[N],ans[N]; int fail[N],ch[N][26],dep[N]; int n,rt=1,tot=1,q[N],w[N]; void build() { int h=0,t=0,x; fail[rt]=rt; for(int i=0;i<26;i++) if(ch[rt][i]==-1) ch[rt][i]=rt; else { fail[ch[rt][i]]=rt; q[++t]=ch[rt][i]; } while(h<t) { x=q[++h]; for(int i=0;i<26;i++) if(ch[x][i]==-1) ch[x][i]=ch[fail[x]][i]; else { fail[ch[x][i]]=ch[fail[x]][i]; q[++t]=ch[x][i]; } } } int main() { scanf("%s",s+1); memset(ch,-1,sizeof(ch)); scanf("%d",&n); int len,x,t; for(int i=1;i<=n;i++) { scanf("%s",s1+1); len=strlen(s1+1);x=rt; for(int i=1;i<=len;i++) { t=s1[i]-‘a‘; if(ch[x][t]==-1) ch[x][t]=++tot; x=ch[x][t]; } dep[x]=len; } build(); x=rt;len=strlen(s+1);tot=0;w[0]=rt; for(int i=1;i<=len;i++) { ans[++tot]=s[i]; x=ch[x][s[i]-‘a‘];w[tot]=x; if(dep[x]){tot-=dep[x];x=w[tot];} } for(int i=1;i<=tot;i++) printf("%c",ans[i]);puts(""); return 0; }
bzoj3940[usaco2015feb]censoring*
bzoj3940[Usaco2015Feb]Censoring题意:有一个S串和一大堆T串,不断地在S串里找最早出现的T串,然后将其删除。S串≤100000,T串总长度≤100000。题解:对所有T串建AC自动机,然后同bzoj3942。注意,本题的AC自动机必须利用所有fail函数建成... 查看详情
[bzoj3940][usaco2015feb]censoring
最近做题成双成对?不是双倍经验就是两题同解。3940 3942给定字典,给定字符串,删去字符串中所有字典内单词。保证不会出现二者包含状况。$nleq1e5,sumlenleq1e5$AC自动机裸题。build出AC自动机后从左到右插入文本串,同时... 查看详情
bzoj3940:[usaco2015feb]censoring
给个长度<=1e5的串s,再给n个模板串总长不超1e5,每次把s中起始位置最早的一个模板串删掉,求最后剩的串。AC自动机,开个栈记一下每次走到哪里,匹配成功后直接在栈里找到这一串的初始位置对应自动机上的节点,从而回... 查看详情
bzoj3940[usaco2015feb]censoring
【题目描述】FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S。他有一个包含n个单词的列表,列表里的n个单词记为t_1...t_N。他希望从S中删除这些单词。 FJ每次在S中找到最早出现的列表中的单词(... 查看详情
bzoj3942:[usaco2015feb]censoring
3942:[Usaco2015Feb]CensoringTimeLimit: 10Sec MemoryLimit: 128MBSubmit: 404 Solved: 221[Submit][Status][Discuss]DescriptionFarmerJohnhaspurchasedasubscriptiont 查看详情
3940.[usaco15feb]censoringac自动机+栈(代码片段)
DescriptionFarmerJohnhaspurchasedasubscriptiontoGoodHooveskeepingmagazineforhiscows,sotheyhaveplenty ofmaterialtoreadwhilewaitingaroundinthebarnduringmilkingsessions.Unfortunately,thelatest 查看详情
bzoj3942[usaco2015feb]censoring*
bzoj3942[Usaco2015Feb]Censoring题意:有一个S串和一个T串,不断地在S串里匹配T串,然后将其删除。S串、T串长度≤1000000。题解:用1、2两个栈,每次将S串的当前字符压入1栈,当前匹配到T串的位置压入2栈,如果匹配出一个T串,则让1... 查看详情
最大生成树bzoj3943[usaco2015feb]superbull
TimeLimit: 10Sec MemoryLimit: 128MBSubmit: 374 Solved: 217[Submit][Status][Discuss]DescriptionBessieandherfriendsareplayinghoofballintheannualSuperbullc 查看详情
bzoj_3942_[usaco2015feb]censoring_kmp
BZOJ_3942_[Usaco2015Feb]Censoring_KMPDescription有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程。InputThefirstlinewillcontainS.Thesecondlinewill... 查看详情
bzoj2015:[usaco2010feb]chocolategivingspfa
因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可#include<iostream>#include<cstdio>#include<queue>usingnamespacestd;constintN=50005,inf=1e9;intn,m,b,h[N],cnt,dis[N];boolv[N];structqweintne,to, 查看详情
bzoj3939[usaco2015feb]cowhopscotch动态开点线段树优化dp
题目描述JustlikehumansenjoyplayingthegameofHopscotch,FarmerJohn‘scowshaveinventedavariantofthegameforthemselvestoplay.Beingplayedbyclumsyanimalsweighingnearlyaton,CowHopscotchalmostalwaysendsindisaster,bu 查看详情
[bzoj3943][usaco2015feb]superbull_kruskal
SuperBullbzoj-3943Usaco-2015Feb题目大意:贝西和她的朋友们在参加一年一度的“犇”(足)球锦标赛。FJ的任务是让这场锦标赛尽可能地好看。一共有N支球队参加这场比赛,每支球队都有一个特有的取值在1-230-1之间的整数编号(即... 查看详情
bzoj3939[usaco2015feb]cowhopscotch
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3939【题解】f[i][j]=s[i-1][j-1]-sum[a[i][j]]用cdq分治来处理横坐标,先处理上面的dp值,再讨论上面部分对下面的贡献,然后分治处理下面的dp值即可。如果加了快读好像排bzojrk1?#include<s... 查看详情
bzoj3942:[usaco2015feb]censoringkmp+栈
好久没写kmp都不会写了……开两个栈,s存当前串,c存匹配位置用t串在栈s上匹配,栈每次入栈一个原串字符,用t串匹配一下,如果栈s末尾匹配了t则弹栈#include<iostream>#include<cstdio>#include<cstring>usingnamespacestd;constintN=1... 查看详情
bzoj3943[usaco2015feb]superbull:最大生成树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3943题意: 有n只队伍,每个队伍有一个编号a[i]。 每场比赛有两支队伍参加,然后选一支队伍淘汰。共进行n-1场比赛,然后比赛结束。 若某场比赛是队伍i和j参加,则该... 查看详情
[bzoj2591][usaco2012feb]nearbycows
2591:[Usaco2012Feb]NearbyCowsTimeLimit:4Sec MemoryLimit:128MBSubmit:149 Solved:89[Submit][Status][Discuss]Description FarmerJohnhasnoticedthathiscowsoftenmovebetweennearbyfi 查看详情
bzoj1651:[usaco2006feb]stallreservations专用牛棚
二次联通门: BZOJ1651:[Usaco2006Feb]StallReservations专用牛棚 权限题放题面DescriptionOhthosepickyN(1<=N<=50,000)cows!TheyaresopickythateachonewillonlybemilkedoversomeprecisetimeintervalA.. 查看详情
[bzoj]1631:[usaco2007feb]cowparty
1631:[Usaco2007Feb]CowPartyTimeLimit:5Sec MemoryLimit:64MBSubmit:866 Solved:624[Submit][Status][Discuss]Description 农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X 查看详情