这题简直比注水猪肉还水QAQ。

以前做过KMP的Censoring单串匹配,果断选择自动AC机w

对短串建自动AC机

长串去机子里匹配

用个栈边匹配边弹出

记得弹出一个串后把匹配点指向栈顶就ojbk

(话说自动AC机也不能自动AC   QAQ)

 #include<cmath>
#include<queue>
#include<cstdio>
#define Zs 13331
#include<cstring>
#include<iostream>
#define QAQ 100100
#include<algorithm>
#define ull unsigned long long
using namespace std;
struct node{
int c;
int num;
node *f;
node *ch[];
node(){
c=,f=NULL;num=;
memset(ch,NULL,sizeof ch);
}
}*last[QAQ];
int n;
char s[][QAQ];
char stack[QAQ];int top=;
node *root=new node();
inline void insert(int id){
node *p=root;int i=,index;
while(s[id][i]){
index=s[id][i]-'a';
if(p->ch[index]==NULL)p->ch[index]=new node();
p=p->ch[index];
++i;
}
p->num=strlen(s[id]+);
}
void GetFail(){
queue<node*>qwq;
for(int i=;i<;i++){
if(root->ch[i]!=NULL)
root->ch[i]->f=root,
qwq.push(root->ch[i]);
else root->ch[i]=root;
}
while(!qwq.empty()){
node *now=qwq.front();qwq.pop();
for(int i=;i<;i++){
if(now->ch[i]!=NULL)
now->ch[i]->f=now->f->ch[i],
qwq.push(now->ch[i]);
else now->ch[i]=now->f->ch[i];
}
}
}
void query(char *s){
node *now=root;int i=;
while(s[i]){
stack[++top]=s[i];
if(now==NULL)now=root;last[top]=now;
now=now->ch[s[i]-'a'];
for(node *j=now;j!=NULL&&j!=root;j=j->f){
int out=j->num;
if(j->f!=NULL&&!j->f->num)j->f=j->f->f;
if(!out)continue;
top-=out;
now=last[top+];
break;
}
++i;
}
}
void puts_out(){
for(int i=;i<=top;i++){
printf("%c",stack[i]);
}
}
int main(){
// freopen("cen .in","r",stdin);
// freopen("cen.out","w",stdout);
scanf("%s",s[]+);
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",s[i]+);
insert(i);
}
GetFail();
query(s[]);
puts_out();
}

丑比代码QAQ

哦还有,这个啥玩意儿Trie图挺闹心的,还得优化

留坑待填QwQ (waiting......)

Censoring【自动AC机】【水题毁我青春】【20190614】的更多相关文章

  1. 关于自动AC机

    嗯,,,,自动AC机 在cena评测时: Const SourcePath:string='incantation'; InputFile:string='incantation.in'; Outpu ...

  2. 论自动AC机

    O(∩_∩)O哈哈~第一篇原创博客.终于结束了我“无敌转载王”的称号了!!!好开心! (⊙v⊙)嗯,看到标题觉得我是神犇的人,请再次仔细看看标题,是“自动AC”,而非“AC自动”哦!这是利用lemon ...

  3. BZOJ-3940:Censoring(AC自动机裸题)

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

  4. 自动AC机qwq(大雾)以及trie图fail图的一些结论

    1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string&g ...

  5. 自动AC机

    可以在lemon和cena环境下使用. #include<iostream> #include<cstdio> #include<cstring> #include ...

  6. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  7. 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...

  8. 水题不AC,自挂二叉树——Chemist

    学长让我们刷USACO的水题果然是有道理的,做了四道挂了两道...细节处理一定要小心!大概都是NOIP Day1 T1的难度,但是一定要考虑全面否则还是凉凉啊. 一.USACO1.1贪婪的送礼者 题目 ...

  9. bzoj usaco 金组水题题解(1)

    UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT. ...

随机推荐

  1. jquery实现点击按钮弹出层和点击空白处隐藏层

    昨天做项目遇到一个问题,和大家分享下,jquery实现点击按钮弹出层和点击空白处隐藏层的问题 if($('.autoBtn').length){                $('.autoBtn' ...

  2. 如何在windows上把你的项目提交到github(转载)

    (1)如何在windows上把你的项目提交到githubhttp://michaelye1988.iteye.com/blog/1637951 (2)github错误提示:fatal:remote o ...

  3. Codeforces Round #525 E - Ehab and a component choosing problem

    题目大意: 在一棵树中 选出k个联通块 使得 这k个联通块的点权总和 / k 最大 并且这k个联通块不相互覆盖(即一个点只能属于一个联通块) 如果有多种方案,找到k最大的那种 给定n 有n个点 给定n ...

  4. LA2218 Triathlon /// 半平面交 oj22648

    题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...

  5. 字典配合split分裂填充

    Sub 配送日报()lastrow = Sheets("运营日报").Range("a1048576").End(xlUp).Rowarr = Sheets(& ...

  6. JAVA算法之简单排序

    冒泡排序: 在概念上是排序算法中最简单的,但是运行起来非常慢,冒泡排序遵循以下几个规则(假如我们现在要给一队打乱的足球队员排序): 比较两个队员 如果左边的队员比右边的高,则交换位置 向右移动一位,比 ...

  7. 6.RDD算子实战

    from pyspark import SparkContext,SparkConf import sys if __name__ == '__main__': if len(sys.argv) != ...

  8. USACO18FEB Platinum

    SlingShot 求数轴上从x到y的最短路( 边长为1),有若干个从xi到yi长度为ti的传送门,每次只能选择其中一个使用. 即求min(|x-y|,min{|a-x|+|b-y|+c}),拆开绝对 ...

  9. CSS压缩

    通过W3C 统一验证工具的检测没有错误后,为了提高加载速度和节约空间(相对来说,css量很少的情况下,几乎没啥区别),可以通过css压缩工具把css进行压缩. w3c css压缩 http://too ...

  10. thinkphp 原样输出

    可以使用literal标签来防止模板标签被解析,例如: 大理石构件 <literal> <if condition="$name eq 1 "> value ...