Censoring【自动AC机】【水题毁我青春】【20190614】
这题简直比注水猪肉还水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】的更多相关文章
- 关于自动AC机
嗯,,,,自动AC机 在cena评测时: Const SourcePath:string='incantation'; InputFile:string='incantation.in'; Outpu ...
- 论自动AC机
O(∩_∩)O哈哈~第一篇原创博客.终于结束了我“无敌转载王”的称号了!!!好开心! (⊙v⊙)嗯,看到标题觉得我是神犇的人,请再次仔细看看标题,是“自动AC”,而非“AC自动”哦!这是利用lemon ...
- BZOJ-3940:Censoring(AC自动机裸题)
Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have p ...
- 自动AC机qwq(大雾)以及trie图fail图的一些结论
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string&g ...
- 自动AC机
可以在lemon和cena环境下使用. #include<iostream> #include<cstdio> #include<cstring> #include ...
- 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ
前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...
- 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...
- 水题不AC,自挂二叉树——Chemist
学长让我们刷USACO的水题果然是有道理的,做了四道挂了两道...细节处理一定要小心!大概都是NOIP Day1 T1的难度,但是一定要考虑全面否则还是凉凉啊. 一.USACO1.1贪婪的送礼者 题目 ...
- bzoj usaco 金组水题题解(1)
UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT. ...
随机推荐
- 2018今日头条湖北省赛【D】
[题目链接]https://www.nowcoder.com/acm/contest/104/C 不知道这题为啥没过.队友现场推的都是对的..233333好像代码写的有问题,下来就很恼火. 题意大概就 ...
- BeanShell Sampler生成uuid
- Activiti学习笔记8 — UserTask私有任务的使用
每一个UserTask都会在Execution表和Task表中各产生一条记录 一.创建流程引擎对象 /** * 1.创建流程引擎对象 */ private ProcessEngine processE ...
- PokerNet-poker recognition: 扑克识别 (6)
文章目录 准备 最终结果 未来改进 准备 机器: Titan XP 12GB, 64GB RAM, 机器非常强,可靠. 下次有机会购买RTX 2080 Ti 试试 最终结果 错误率可以达到万分之一,非 ...
- [笔记]Laravel TDD 胡乱记录
TDD: 测试驱动开发(Test-Driven Development),TDD的原理是在开发功能代码之前,先编写单元测试用例代码,测试代码确定需要编写什么产品代码. -- 载自TDD百度百科 参考 ...
- CF930E Coins Exhibition
题意:平面上一共有k个硬币(k<=1e9),给你n个区间这些区间中至少有一个硬币反面朝上,m个区间中至少有一个硬币正面朝上.问有多少种硬币放置方案?n,m<=100005. 标程: #in ...
- mui--使用mui中的图文表格组件时出现一条横线的解决方法
最近做的微信公众号点击链接跳转到H5页面,该H5页面使用mui做的,遇到的商品列表页出现一个横线的问题, 这个是修改前的图片 解决方法: <style type="text/css&q ...
- 分享安装Apache、MySQL、PHP、LAMP的完整教程
Operation timed out after 30000 milliseconds with 0 out of -1 bytes received请注意,在Linux中输入密码时,不会显示您输入 ...
- cocos2D-X LUA 非常简单的一个贪吃蛇案例
--[[ 贪吃蛇 ]] local RetroSnaker = class("RetroSnaker", function() return cc.Layer:create(); ...
- thinkphp ASSIGN标签
ASSIGN标签用于在模板文件中赋值变量,用法如下: 直线电机厂家 <assign name="var" value="123" /> 在运行模板的 ...