链接

解码之后是跟普通的自动机求解一下的,只不过解码比较恶心,512=》N》=0 ,所以不能用字符串来存,需要转换成整数来做。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 53769
#define NN 15010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
const int child_num = ;
char s[NN],vir[NN];
int di[NN*],od[NN],vv[NN];
bool f[N];
class ACAutomation
{
private:
int ch[N][child_num];
int val[N];
int fail[N];
int Q[N];
int id[];
int sz;
// int dp[2][N][1<<10];
public:
void init()
{
fail[] = ;
for(int i = ; i < child_num; i++)
id[i] = i;
}
void reset()//初始化
{
memset(ch[],,sizeof(ch[]));
memset(val,,sizeof(val));
sz = ;
}
void insert(int *a,int key,int k)//建立trie树
{
int p = ;
for( int i = ; i < k ; i++)
{
int c = id[a[i]];
if(ch[p][c]==)
{
memset(ch[sz],,sizeof(ch[sz]));
ch[p][c] = sz++;
}
p = ch[p][c];
}
val[p] += key;
}
void construct()//构建fail指针
{
int head = ,tail = ,i;
for(i = ;i < child_num ; i++)
{
if(ch[][i])
{
fail[ch[][i]] = ;
Q[tail++] = ch[][i];
}
}
while(head!=tail)
{
int u = Q[head++];
for(i = ;i < child_num ;i ++)
{
if(ch[u][i]!=)
{
Q[tail++] = ch[u][i];
fail[ch[u][i]] = ch[fail[u]][i];
}
else
ch[u][i] = ch[fail[u]][i];
}
}
}
int work(int *s,int k)
{
int p = ,ans = ;
memset(f,,sizeof(f));
for(int i = ; i < k ; i++)
{
int d = id[s[i]];
p = ch[p][d];
int tmp = p;
while(tmp!=&&!f[tmp])
{
ans+=val[tmp];
f[tmp] = ;
tmp = fail[tmp];
}
}
return ans;
}
}ac;
int change(char *a)
{
int i,k = strlen(a),j;
int g = ,gg,num = ;
for(i = ;i < k ; i++)
{
if(a[i]=='=')
{
num++;
continue;
}
int x = od[a[i]];gg=;
for(j=;j>=;j--)
{
di[g++]=((x&(<<j))>);
}
}
if(num==)
g-=;
else if(num==)
g-=;
gg = ;
int y = ;
for(j = ;j < g ; j++)
{
y+=di[j]*(<<(-j%));
if((j+)%==)
{
vv[gg++] = y;
y = ;
}
}
return g/;
}
int main()
{
int n,i,m;
for(i = 'A' ; i <= 'Z' ; i++)
od[i] = i-'A';
for(i = 'a' ; i <= 'z' ; i++)
od[i] = +i-'a';
for(i = ''; i <= '' ; i++)
od[i] = +i-'';
od['+'] = ,od['/'] = ;
ac.init();
while(scanf("%d",&n)!=EOF)
{
ac.reset();
for(i = ; i <= n; i++)
{
scanf("%s",vir);
int len = change(vir);
ac.insert(vv,,len);
}
ac.construct();
scanf("%d",&m);
for(i = ; i <= m ;i++)
{
scanf("%s",s);
int len = change(s);
printf("%d\n",ac.work(vv,len));
}
puts("");
}
return ;
}

zoj3430Detect the Virus(ac自动机)的更多相关文章

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

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

  2. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  3. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

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

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

  5. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

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

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

  7. AC自动机 - 多模式串的匹配 --- HDU 3695 Computer Virus on Planet Pandora

    Problem's Link Mean: 有n个模式串和一篇文章,统计有多少模式串在文章中出现(正反统计两次). analyse: 好久没写AC自动机了,回顾一下AC自动机的知识. 本题在构造文章的时 ...

  8. [AC自动机]HDOJ3695 Computer Virus on Planet Pandora

    题意:给t.n,t个案例,n个字符串 下面给n+1个字符串,n个互不相同的小串,最后一个是模式串 模式串会出现[qx]的形式,q为数字,x为一个字母 问n个小串在模式串中出现的个数,正着出现.反着出现 ...

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

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

随机推荐

  1. 生产环境下的mysql主从复制

    一.主mysql配置:1.配置my.cnf[mysqld]server-id = 10 #服务器标示log-bin= mysql-bin #二进制日志binlog-do-db=mydb #需要同步的数 ...

  2. 浅谈Entity Framework 增删改查和事务操作

    1.增加对象 DbEntity db = new DbEntity(); //创建对象实体,注意,这里需要对所有属性进行赋值(除了自动增长主键外),如果不赋值,则会数据库中会被设置为NULL(注意是否 ...

  3. C 数组模拟阶乘运算

    #include <stdio.h> void rdump(int arr[],int len) { ; ;i >= ; --i) { printf("%d",a ...

  4. LeetCode Count of Range Sum

    原题链接在这里:https://leetcode.com/problems/count-of-range-sum/ 题目: Given an integer array nums, return th ...

  5. AngularJS Best Practices: ui-router

    ui-router is a 3rd-party module and is very powerful. It supports everything the normal ngRoute can ...

  6. Markdown 语法和 MWeb 写作使用说明

    ---恢复内容开始--- # Markdown 语法和 MWeb 写作使用说明 Markdown 的设计哲学 Markdown 的目標是實現「易讀易寫」. 不過最需要強調的便是它的可讀性.一份使用 M ...

  7. ucos 学习

    1.UCOSII 早期版本只支持 64 个任务,但是从 2.80 版本开始,支持任务数提高到 255 个,不过对我们来说一般 64 个任务都是足够多了,一般很难用到这么多个任务. UCOSII 保留了 ...

  8. C语言回顾-运算符和循环

    1.运算符 连接操作数,构成表达式 按功能划分: 1)算术运算符 + - *  / % 2)关系运算符 3)逻辑运算符 4)按位运算符 按操作数划分: 1)单目运算符 2)双目运算符 3)三目运算符 ...

  9. 50个常用的JQuery代码

    1. 如何创建嵌套的过滤器 //允许你减少集合中的匹配元素的过滤器, //只剩下那些与给定的选择器匹配的部分.在这种情况下, //查询删除了任何没(:not)有(:has) //包含class为“se ...

  10. .Net程序员安卓学习之路4:使用xutils Get Post数据

    前面使用了一些网络上找来的类进行网络访问,后来发现了安卓开发中有一个国人写的类库xutils比较全面,也比较经典,故后续使用xutils类库进行记录. 本例服务端使用WCF来实现,写好的WCF服务端在 ...