这题主要就是解码过程很恶心,不能用char存,一共wa了20发

题意:先给n串加密后的字符,然后m串加密后的字符,解码之后求n对应每个m的匹配数,很显然的ac自动机

加密过程是先用对应ascii表的标号来代替字符,然后把这些数字转换成8位的二进制,全部连起来,然后每6位算一个数,用二进制算成整数,最后用这些整数来映射给定的表

题解:反解密就好了,要注意细节,很容易Segmentation Fault,最后算出来的字符用int存,然后跑ac自动机就行了

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=*+,maxn=+,inf=0x3f3f3f; inline void debug(){cout<<"fuck"<<endl;} char s[];
int de[],sz;
int digit[*];
struct Trie{
int tot,root;
int Next[N][],fail[N],End[N];
int newnode()
{
for(int i=;i<;i++)
Next[tot][i]=-;
End[tot]=;
return tot++;
}
void init()
{
tot=;
root=newnode();
}
void insertstring(int id)
{
int now=root;
for(int i=;i<sz;i++)
{
if(Next[now][de[i]]==-)
Next[now][de[i]]=newnode();
now=Next[now][de[i]];
}
End[now]=id;
}
void build()
{
queue<int>q;
fail[root]=root;
for(int i=;i<;i++)
{
if(Next[root][i]==-)Next[root][i]=root;
else
{
fail[Next[root][i]]=root;
q.push(Next[root][i]);
}
}
while(!q.empty())
{
int now=q.front();
q.pop();
for(int i=;i<;i++)
{
if(Next[now][i]==-)Next[now][i]=Next[fail[now]][i];
else
{
fail[Next[now][i]]=Next[fail[now]][i];
q.push(Next[now][i]);
}
}
}
}
bool vis[];
int query(int n)
{
int now=root;
memset(vis,,sizeof vis);
for(int i=;i<sz;i++)
{
now=Next[now][de[i]];
int te=now;
while(te!=root)
{
if(End[te])vis[End[te]]=;
te=fail[te];
}
}
int res=;
for(int i=;i<=n;i++)
if(vis[i])
res++;
return res;
}
};
int getnew(char x)
{
if(x>='A'&&x<='Z')return x-'A';
if(x>='a'&&x<='z')return x-'a'+;
if(x>=''&&x<='')return x-''+;
if(x=='+')return ;
else return ;
}
void change(char s[])
{
sz=;
int len=strlen(s);
while(s[len-]=='=')len--;
vector<int>v;
for(int i=;i<len;i++)v.pb(getnew(s[i]));
memset(digit,,sizeof digit);
for(int i=;i<v.size();i++)
{
for(int j=*(i+)-;j>=*i;j--)
{
if(v[i]&)digit[j]=;
v[i]/=;
}
}
sz=v.size()*/;
for(int i=;i<sz;i++)
{
de[i]=;
for(int j=*i;j<*(i+);j++)
de[i]=(de[i]<<)+digit[j];
// cout<<de[i]<<" ";
}
// cout<<endl;
}
Trie ac;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
while(~scanf("%d",&n))
{
ac.init();
for(int i=;i<=n;i++)
{
scanf("%s",s);
change(s);
ac.insertstring(i);
}
ac.build();
int k;
scanf("%d",&k);
while(k--)
{
scanf("%s",s);
change(s);
printf("%d\n",ac.query(n));
}
puts("");
}
return ;
}
/******************** ********************/

ZOJ - 3430 ac自动机的更多相关文章

  1. HDU - 2222,HDU - 2896,HDU - 3065,ZOJ - 3430 AC自动机求文本串和模式串信息(模板题)

    最近正在学AC自动机,按照惯例需要刷一套kuangbin的AC自动机专题巩固 在网上看过很多模板,感觉kuangbin大神的模板最为简洁,于是就选择了用kuangbin大神的模板. AC自动机其实就是 ...

  2. Detect the Virus ZOJ - 3430 AC自动机

    One day, Nobita found that his computer is extremely slow. After several hours' work, he finally fou ...

  3. ZOJ 3494 (AC自动机+高精度数位DP)

    题目链接:  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3494 题目大意:给定一些被禁止的BCD码.问指定范围内不含有 ...

  4. BCD Code ZOJ - 3494 AC自动机+数位DP

    题意: 问A到B之间的所有整数,转换成BCD Code后, 有多少个不包含属于给定病毒串集合的子串,A,B <=10^200,病毒串总长度<= 2000. BCD码这个在数字电路课上讲了, ...

  5. Searching the String ZOJ - 3228 AC自动机查询升级版

    题意:先给你一个不超过1000000长度的大串s:接下来输入一个n代表接下来输入的小串个数,小串长度不超过6. 小串分两种类型0和1类型. 0类型表示小串在大串中的最大匹配个数就是常规的AC自动机的做 ...

  6. ZOJ 3430 Detect the Virus(AC自动机)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3430 题意:给你n个编码后的模式串,和m个编码后的主串,求原来主 ...

  7. ZOJ - 3430 Detect the Virus —— AC自动机、解码

    题目链接:https://vjudge.net/problem/ZOJ-3430 Detect the Virus Time Limit: 2 Seconds      Memory Limit: 6 ...

  8. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

  9. ZOJ 4114 Detect the Virus(AC自动机)

    Detect the Virus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Nobita found that his co ...

随机推荐

  1. Qt 如何像 VS 一样创建项目模版?

    qt 存储模版路径位置:Qt\Qt5.9.5\Tools\QtCreator\share\qtcreator\templates\wizards 在里面随意复制一个模版,修改三项即可在 qt 中显示该 ...

  2. django实现密码加密的注册(数据对象插入)

    在 django实现密码非加密的注册(数据对象插入)的基础上,我们对视图和注册页面进行了简单修改 视图 from django.shortcuts import render,redirect,ren ...

  3. java NIO 模型(一)

    1. 阻塞I/O通信模型 1.性能:一连接一线程模型导致服务端的并发接入数和系统吞吐量受到极大限制 2.可靠性:由于IO操作采用同步阻塞模式,当网络拥塞或者逻辑处理缓慢会导致IO线程被挂住,阻塞时间无 ...

  4. 001-web基本程序搭建

    一.IDEA创建项目 1.基本项目创建 1.1.基本步骤 1.Create New Project [File→New→Project]→New Project 2.maven→group.artif ...

  5. Kafka的架构

    1.Kafka整体架构    一个典型的Kafka集群中包含若干producer(可以是web前端产生的page view,或者是服务器日志,系统CPU.memory等),若干broker(Kafka ...

  6. PHP生成缩略图,控制图片质量,支持.png .jpg .gif

    namespace common\components; class ResizeImageHelper { public $type;//图片类型 public $width;//实际宽度 publ ...

  7. iOS UIScrollView 滚动到当前展示的视图居中展示

    需求展示: 测试效果1 first uiscrollView  宽度 为屏幕宽度   滚动步长 为 scroll 宽度的1/3   分析: 这个是最普通版 无法使每一次滚动的结果子视图居中展示, WA ...

  8. 024_MapReduce中的基类Mapper和基类Reducer

    内容提纲 1) MapReduce中的基类Mapper类,自定义Mapper类的父类. 2) MapReduce中的基类Reducer类,自定义Reducer类的父类. 1.Mapper类 API文档 ...

  9. JAVA 判断对象内容是否含有空值

    简单判断对象是否含有NULL值,以及信息描述. package com.sicdt.sicsign.bill.api.util; import java.lang.reflect.Invocation ...

  10. spring data jpa是什么?

    JPA是一个Java编程语言接口规范,Hibernate ORM是JPA规范的一个实现.   Spring Data JPA能干什么 在开始之前,先举个简单的例子. 一张表user有三个字段,id.n ...