Hdu3695Computer Virus on Planet Pandora

2024-01-30 05:38

本文主要是介绍Hdu3695Computer Virus on Planet Pandora,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Problem Description

Aliens on planet Pandora also write computer programs like us. Their programs only consist of capital letters (‘A’ to ‘Z’) which they learned from the Earth. On
planet Pandora, hackers make computer virus, so they also have anti-virus software. Of course they learned virus scanning algorithm from the Earth. Every virus has a pattern string which consists of only capital letters. If a virus’s pattern string is a substring of a program, or the pattern string is a substring of the reverse of that program, they can say the program is infected by that virus. Give you a program and a list of virus pattern strings, please write a program to figure out how many viruses the program is infected by.

Input

There are multiple test cases. The first line in the input is an integer T ( T<= 10) indicating the number of test cases.
For each test case:
The first line is a integer n( 0 < n <= 250) indicating the number of virus pattern strings.
Then n lines follows, each represents a virus pattern string. Every pattern string stands for a virus. It’s guaranteed that those n pattern strings are all different so there
are n different viruses. The length of pattern string is no more than 1,000 and a pattern string at least consists of one letter.
The last line of a test case is the program. The program may be described in a compressed format. A compressed program consists of capital letters and
“compressors”. A “compressor” is in the following format:
[qx]
q is a number( 0 < q <= 5,000,000)and x is a capital letter. It means q consecutive letter xs in the original uncompressed program. For example, [6K] means
‘KKKKKK’ in the original program. So, if a compressed program is like:
AB[2D]E[7K]G
It actually is ABDDEKKKKKKKG after decompressed to original format.
The length of the program is at least 1 and at most 5,100,000, no matter in the compressed format or after it is decompressed to original format.

Output

For each test case, print an integer K in a line meaning that the program is infected by K viruses.

Sample Input

3
2
AB
DCB
DACB
3
ABC
CDE
GHI
ABCCDEFIHG
4
ABB
ACDEE
BBB
FEEE
A[2B]CD[4E]F

Sample Output

0
3
2

Hint

In the second case in the sample input, the reverse of the program is ‘GHIFEDCCBA’, and ‘GHI’ is a substring of the reverse, so the program is infected
by virus ‘GHI’.


题目大意

给出n(n<250)个长度小于1000的短字符串,给出一个压缩后的长字符串(展开后长度小于5100000),问长字符串(可翻转)中有多少个短字符串

Solution

AC自动机模板题

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;#define N 250011
#define L 5100011int tree[N][26],fail[N],p[N],vis[N],tot,n,t,len,x,ll;
int now,ans,ii,i,j,v,k,l;
char ch[L],s[L];void insert()
{now=0;for (i=1;i<=len;i++){if (tree[now][s[i]-'A']==0) tree[now][s[i]-'A']=++tot;now=tree[now][s[i]-'A'];}p[now]+=1;
}queue<int> Q;void get()
{for (i=0;i<=25;i++)if (tree[0][i]!=0) Q.push(tree[0][i]);while (!Q.empty()){now=Q.front(); Q.pop();for (i=0;i<=25;i++){v=tree[now][i];k=tree[fail[now]][i];if (v!=0) fail[v]=k,Q.push(v);else tree[now][i]=k;}}
}void query()
{ans=0,now=0;for (i=1;i<=len;i++){now=tree[now][s[i]-'A'];for (j=now;j!=0;j=fail[j]){if (vis[j]==1) break;ans+=p[j];p[j]=0;vis[j]=1;}}now=0;for (i=len;i>=1;i--){now=tree[now][s[i]-'A'];for (j=now;j!=0;j=fail[j]){if (vis[j]==1) break;ans+=p[j];p[j]=0;vis[j]=1;}}printf("%d\n",ans);
}void init()
{memset(tree,0,sizeof(tree));memset(fail,0,sizeof(fail));memset(p,0,sizeof(p));memset(vis,0,sizeof(vis));tot=0;scanf("%d",&n);for (l=1;l<=n;l++){scanf("\n%s",s+1);len=strlen(s+1);insert();}
}int main()
{scanf("%d",&t);for (ii=1;ii<=t;ii++){init();get();scanf("\n%s",ch+1);len=0;ll=strlen(ch+1);for (i=1;i<=ll;i++){if (ch[i]=='['){x=0;while (ch[i+2]!=']' && i<=ll){i++;x=x*10+int(ch[i]-'0');}for (j=1;j<=x;j++)s[++len]=ch[i+1];i+=2;}else s[++len]=ch[i];}query();}return 0;
}

ps

刚写完TLE和MLE和RT轮流轰炸,心态极崩,
然后被ymw(dalao) 发现,tot每次没清零,心塞啊啊啊啊~

这篇关于Hdu3695Computer Virus on Planet Pandora的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/659248

相关文章

Metasploit - Tips for Evading Anti-Virus

绕过杀毒软件,有许多钟方法。此处介绍一种,编写python程序调用shellcode,并使用Pyinstaler将python程序编译为exe程序。 准备工作:(Windows XP环境下编译) 将Python程序编译为exe,需要Python主程序,pywin32库,Pyinstaller(直接解压到C盘)。如果编译过程中出现错误提示,请按照指示解决问题。安装过程不是很复杂,在此不

[amanhardikar] - virus-classification

From: http://www.amanhardikar.com/mindmaps/virus-classification.png

The Art of Computer Virus Research and Defense

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Symantec's chief antivirus researcher has written the definitive guide to contemporary virus threats, d

一文读懂BTC生态新贵Giants Planet,将L2与现实世界整合

前言 获新加坡主权基金鼎力扶持,Giants Planet将引爆Web3新风向。 随着年前BTC现货 ETF 的获批,加密世界涌入大量的资金,BTC价格也成功突破新高。与之相比,传统金融的弊端日益凸显,且大部分资产涨幅都低于BTC,这让传统公司以及部分国家地区对于日渐兴起的BTC产生极大的兴趣。 如何能够搭上BTC的“顺风车”成了其困扰的问题,单纯购买BTC或许已经成为过去式。

zerotier自建planet

ZeroTier 是一个由 C++ 开发的软交换机,可以让多台内网机器组成一个私有的局域网。ZeroTier 的节点分为三类: Planet Server: 官方的根服务器,用于记录和配置每个局域网下客户端信息(以下简称 Planet);Moon Server: 官方推荐的私有 Planet Server 的部署方法,在默认 Planet 无法访问的时候承担 Planet 的作用(以下简称 Mo

[planet] Rudiger Ehlers - Formal Verification of Piece-Wise Linear Feed-Forward Neural Networks

Title: Formal Verification of Piece-Wise Linear Feed-Forward Neural NetworksAuthor: Rudiger Ehlers 1 Introduction 2 Preliminaries Satisfiability solvers: 可满足性(SAT)求解器检查布尔公式是否具有可满足的赋值。 该公式通常要求是连词形

virus.win32.parite.H病毒的查杀方法

转载地址:http://blog.csdn.net/wuxiaokaixinguo/article/details/12126391       virus.win32.parite.H病毒的查杀方法    昨天电脑中了virus.win32.parite.H病毒,搞了2个多小时终于搞定了。下面记录下我的解决方法。 第一步:下载Win32.Parite病毒专杀工具 下载地址

Pandora:Android调试利器

Pandora 是一款无需ROOT、可以直接在 应用内 查看和修改包括网络、数据库、UI等的Android工具箱,适合开发和测试阶段的各种问题的快速定位。 功能 查看每条网络请求的详细日志,例如headers、response等; 查看自身应用的内部存储系统; 查看所有数据库,支持直接进行增删改查操作; 查看并编辑所有Shared Preference; 预览当前页面的视图层级、查看/

HDU 3695 Computer Virus on Planet Pandora and HDU 2896 病毒侵袭(AC自动机裸题)

题目大意 都是给出几个病毒模式串,然后再给一个串看其中有多少个病毒,不同的是3695要求将串反转一次,2896是对于每个网站按照标号顺序输出含有的病毒串和含有病毒的网站总数。 解题思路 都是按照给的病毒模式串建立AC自动机,3695将串正向和反向均匹配一次,2896是将记录每个匹配到的字符串然后按照标号顺序输出,注意要对已经匹配到的病毒串进行标记,避免重复计数。 另外我的代码G++MLE,

Esri、联合国和GEO Blue Planet发布水资源健康工具

合作将为沿海国家提供数据,以帮助改善海洋水质 加州雷德兰兹--(美国商业资讯)--全球位置情报领导者Esri今天宣布,将向希望改善沿海水质的国家提供一款新的免费开放工具。这款工具采用实时分析,帮助各国监测沿海水质,并利用这些信息来指导政策制定和减少地源污染。 来自Esri、联合国环境规划署和GEO Blue Plane的团队通过合作开发出了这种新的统计方法,利用卫星数据和地理空间技术来支持联合