HDU-3695 Computer Virus on Planet Pandora
HDU-3695 Computer Virus on Planet Pandora
题意:电脑中病毒了, 现在n钟病毒指令, 然后有一个电脑指令, 看一下这个电脑指令中了几个病毒, 如果电脑种了某一个病毒, 那么就有子串是病毒指令, 或者 子串的反串是病毒指令, 现在问电脑指令一共感染了多少病毒。
题解:AC自动机,然后正向匹配一遍, 反向匹配一遍。
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
typedef pair<int,int> pll;
const int N = 1e6+;
int tot = ;
char str[N*], tmp[N*];
int trie[N*][], cnt[N*], fair[N*];
void init(){
for(int i = ; i < tot; i++){
for(int j = ; j < ; j++)
trie[i][j] = ;
}
tot = ;
}
void Insert(){
int rt = , len = strlen(str);
for(int i = ; i < len; i++){
int id = str[i] - 'A';
if(!trie[rt][id]) {
cnt[tot] = ;
fair[tot] = ;
trie[rt][id] = tot++;
}
rt = trie[rt][id];
}
cnt[rt]++;
}
void Build_tree(){
queue<int> q;
q.push();
int p;
while(!q.empty()){
int tmp = q.front();
q.pop();
for(int j = ; j < ; j++){
if(trie[tmp][j]){
if(tmp == )
fair[trie[tmp][j]] = ;
else {
p = fair[tmp];
while(p){
if(trie[p][j]){
fair[trie[tmp][j]] = trie[p][j];
break;
}
else p = fair[p];
}
if(!p) fair[trie[tmp][j]] = ;
}
q.push(trie[tmp][j]);
}
}
}
}
int Find(int len){
int ret = , rt = ;
for(int i = ; i < len; i++){
int id = str[i] - 'A';
while(rt != && !trie[rt][id]) rt = fair[rt];;
if(trie[rt][id]) rt = trie[rt][id];
int p = rt;
while(p != ){
if(cnt[p] >= ){
ret += cnt[p];
cnt[p] = -;
}
else break;
p = fair[p];
}
}
rt = ;
for(int i = len - ; i >= ; i--){
int id = str[i] - 'A';
while(rt != && !trie[rt][id]) rt = fair[rt];
if(trie[rt][id]) rt = trie[rt][id];
int p = rt;
while(p != ){
if(cnt[p] >= ){
ret += cnt[p];
cnt[p] = -;
}
else break;
p = fair[p];
}
}
return ret;
}
int main(){
int t;
scanf("%d", &t);
while(t--){
int n;
init();
scanf("%d", &n);
while(n--){
scanf("%s", str);
Insert();
}
Build_tree();
scanf("%s", tmp);
int len = strlen(tmp);
int ccc = ;
for(int i = ; i < len; i++){
if(tmp[i] != '['){
str[ccc++] = tmp[i];
}
else {
int _c = ;
i++;
while(isdigit(tmp[i]))
_c = _c * + (int)(tmp[i]-''), i++;
while(_c--)
str[ccc++] = tmp[i];
i++;
}
}
printf("%d\n", Find(ccc));
}
return ;
}
HDU-3695 Computer Virus on Planet Pandora的更多相关文章
- hdu 3695 Computer Virus on Planet Pandora(AC自己主动机)
题目连接:hdu 3695 Computer Virus on Planet Pandora 题目大意:给定一些病毒串,要求推断说给定串中包括几个病毒串,包括反转. 解题思路:将给定的字符串展开,然后 ...
- hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- hdu ----3695 Computer Virus on Planet Pandora (ac自动机)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- HDU 3695 Computer Virus on Planet Pandora (AC自己主动机)
题意:有n种病毒序列(字符串),一个模式串,问这个字符串包括几种病毒. 包括相反的病毒也算.字符串中[qx]表示有q个x字符.具体见案列. 0 < q <= 5,000,000尽然不会超, ...
- AC自动机 - 多模式串的匹配 --- HDU 3695 Computer Virus on Planet Pandora
Problem's Link Mean: 有n个模式串和一篇文章,统计有多少模式串在文章中出现(正反统计两次). analyse: 好久没写AC自动机了,回顾一下AC自动机的知识. 本题在构造文章的时 ...
- 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 ...
- HDU 3695 / POJ 3987 Computer Virus on Planet Pandora
Computer Virus on Planet Pandora Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1353 ...
- 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 ...
随机推荐
- EF Core的Code First 基础
一.创建实体类与映射类 通过NuGet引用Microsoft.EntityFrameworkCore 1.创建实体类 Code First可以通过为实体类字段添加相应特性,来创建对应的字段类型等,举例 ...
- 定时延时设计FPGA
以50MHZ时钟为例,进行1秒钟延时,并输出延时使能信号. 首先计算需要多少次计时,MHZ=10的六次方HZ.T=20ns 一秒钟需要计时次数为5的七次方即5000_0000. 然后计算需要几位的寄存 ...
- Micropython TPYBoard v102 温湿度短信通知器(基于SIM900A模块)
前言 前段时间看了追龙2,感受就是如果你是冲着追龙1来看追龙2的话,劝你还是不要看了,因为追龙2跟追龙1压根没什么联系,给我的感觉就像是看拆弹专家似的,估计追龙2这个名字就是随便蹭蹭追龙1的热度来的. ...
- Linux基础用户管理
一.用户管理 (一).用户和组的基本概念 Users and groups:. Every process (running program) on the system runs as a part ...
- Activiti6系列(1)- 核心数据库表及字段注释说明
前言 本文是根据<疯狂工作流讲义-Activiti6.0>一书中提取过来的,有兴趣的可以去当当网买这本书,讲的很不错,最后还有实战案例. 虽然是提取过来的,但完全靠手打梳理,觉得有用的小伙 ...
- caddy & grpc(3) 为 caddy 添加一个 反向代理插件
caddy-grpc 为 caddy 添加一个 反向代理插件 项目地址:https://github.com/yhyddr/caddy-grpc 前言 上一次我们学习了如何在 Caddy 中扩展自己想 ...
- 结构型设计模式——适配器模式(Go)
适配器模式: 适配器模式是用于当别人提供的对象或接口中的方法或者其它属性啥的和我们的重复了,或者看的不顺眼.名字太长了记不住,而将其包装到一个对象中,然后通过你感觉自己舒服的方式或者方法名字去间接的调 ...
- quick-cocos2dx在eclipse下的lua调试
文中大部分内容来自http://cn.quick-x.com/?p=253,绿色标记部分为修改部分. 配置编译环境的基本步骤: 安装 Visual Studio 2012 安装 Java SDK 安装 ...
- TP5使用API时不可预知的内部异常
最常见的错误形式例如 controller不存在或者 action不存在之类的 我们第一时间想到的 就是 使用 try{}catch(){} 来捕获 例如: /** * show方法在common里定 ...
- Zabbix-绘制动态拓扑图基础篇
一.实验环境 1.1 zabbix 4.0.2 二.实验需求介绍 公司希望网络拓扑能够动态反应物理接口的状态或者业务的状态,希望将网络拓扑显示到大屏上 三.Zabbix在绘制拓扑的优缺点 3.1 优点 ...