这题简直比注水猪肉还水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. Vmware Centos7 配置静态 ip 和 使宿主机和虚拟机互相 ping 通

    NAT 方式1. 配置静态 ipVmware 安装 Centos7 可以参考 https://blog.csdn.net/guo_ridgepole/article/details/78973763 ...

  2. STM32---初学者用库函数好还是直接对寄存器操作比较好

    引用:http://blog.csdn.net/u010349006/article/details/416 首先,两个都是C语言.从51过渡过来的话,就先说寄存器操作.每个MCU都有自己的寄存器,5 ...

  3. Activiti学习笔记目录

    1.Activiti学习笔记1 — 下载与开发环境的配置: 2.Activiti学习笔记2 — HelloWorld: 3.Activiti学习笔记3 — 流程定义: 4.Activiti学习笔记4 ...

  4. flink widow&window funcion&水印

    在定义了窗口分配器之后,我们需要为每一个窗口明确的指定计算逻辑,这个就是窗口函数要做的事情, 当系统决定一个窗口已经准备好执行之后,这个窗口函数将被用来处理窗口中的每一个元素(可能是 分组的). 谁可 ...

  5. MD5/SHA1/Hmac_SHA1

    1.MD5 #import <CommonCrypto/CommonDigest.h> + (NSString *) md5:(NSString *) input { const char ...

  6. list集合排序3

    java list按照元素对象的指定多个字段属性进行排序 转载 2016年12月27日 11:39:02 见: http://blog.csdn.net/enable1234___/article/d ...

  7. 取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏

    取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏,在MainActivity中添加以下代码: getWindow().clearFlags(WindowManager.LayoutP ...

  8. Java怎样获取字符串最后出现的位置

    lastIndexOf();表示获取字符串最后出现的位置,倒数的位置 @Test /** * lastIndexOf();//获取字符串最后出现的位置,倒数的位置 * */ public void f ...

  9. 数据库实例性能调优利器:Performance Insights

    Performance Insights是什么 阿里云RDS Performance Insights是RDS CloudDBA产品一项专注于用户数据库实例性能调优.负载监控和关联分析的利器,以简单直 ...

  10. dos中文显示乱码怎么办?

    其实只需要一条命令 chcp 65001 执行该操作后,代码页就被变成UTF-8了 也可是GBK,  命令式:  chcp  936 2.修改窗口属性,改变字体 在命令行标题栏上点击右键,选择&quo ...