这题主要就是解码过程很恶心,不能用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. 回顾: Python面向对象三大特性

    继承 待整理^_^ 封装 待整理^_^ 多态 待整理^_^

  2. 常用mongo语句

    只列出指定字段db.getCollection('PUBLICACCOUNTS').find({},{NickName:1,UserName:1,FID:1,_id:0})获取微信公众号列表db.ge ...

  3. IIS 6.0上部署.NET 4.0网站

    最近需要把VS2010开发的网站部署到Windows Server 2003的服务器上去, Windows Server 2003操作系统自带的为IIS 6.0,IIS 6.0一般只支持.NET 2. ...

  4. JSP页面传递参数乱码问题整理

    1.JSP页面之间传递中文参数乱码 (1).a.jsp中正常传递参数,b.jsp 中 <% String projectName = new String(request.getParamete ...

  5. Linux基础系列:常用命令(4)_系统监控

    1. 系统监视和进程控制工具—top和free 1) top命令的功能:top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. 2) ...

  6. POJ 3468 A Simple Problem with Integers 【线段树】

    题目链接 http://poj.org/problem?id=3468 思路 线段树 区间更新 模板题 在赋初始值的时候,按点更新区间就可以 AC代码 #include <cstdio> ...

  7. Ajax+Spring MVC实现跨域请求(JSONP)

    背景: AJAX向后台(springmvc)发送请求,报错:已阻止交叉源请求:同源策略不允许读取 http://127.0.0.1:8080/DevInfoWeb/getJsonp 上的远程资源.可 ...

  8. C51数据类型

  9. jQuery 中让我误解的那些方法

    至今我都不能说把 jQuery 中的方法在实践中都用了一遍, 一部分是用不到,一部分则是我未能体会它的魅力, 所以今天就来收录一下,那些从我们之间溜走的美丽. $.fn.add() 一开始对它的理解就 ...

  10. java配置好jdk-bash: /usr/bin/java: No such file or directory

    在 Linux 系统中安装 JDK 环境,配置好环境变量后,输入 java.javac 或者 java -version 等时,都提示如下错误: -bash: /usr/local/java/bin/ ...