
字符串
文章平均质量分 71
CCloth
这个作者很懒,什么都没留下…
展开
-
[manacher][hash]Magic Spells 2022牛客多校第9场 G
在manacher中心扩展的时候一定会遍历到所有的本质不同的回文子串,因为继承镜像位置的扩展长度并不会产生新的回文子串,所有新的回文子串都需要通过中心扩展得到,而中心扩展的次数平均为len级别的,所以通过manacher就能够O(n)找到所有本质不同的回文子串,对于每个字符串都跑一遍manacher,由于直接往map中丢string可能会T,所以可以丢字符串的哈希值,而单哈希是很容易被卡的,所以这道题要用双哈希。...原创 2022-08-15 20:38:12 · 231 阅读 · 0 评论 -
[manacher/二分+哈希]KFC Crazy Thursday 2022牛客多校第5场 G
由于二分+哈希思路比较明显而且代码也很好写,就只说下解题思路,以'k'为例,首先需要维护出来前i个字符中有多少个'k'出现,这点是为了后面快速得到区间内'k'的出现次数,之后的步骤就和求最长回文子串一样了,O(n)枚举回文中心,对于每个中心O(logn)二分得到最长回文长度,然后这个中心位置对于答案的贡献就是最长回文串中'k'出现次数+1再除2,为什么要+1?这主要是考虑到中心位置字符本身就是'k'的情况。给出一个长度为n的字符串,分别求以'k'、'f'和'c'结尾的回文子串个数。...原创 2022-08-01 23:47:43 · 1265 阅读 · 0 评论 -
[好题][manacher][kmp]Tricky and Clever Password Codeforces30E
题目描述在年轻的时候,我们故事中的英雄——国王 Copa——他的私人数据并不是完全安全地隐蔽。对他来说是,这不可接受的。因此,他发明了一种密码,好记又难以破解。后来,他才知道这种密码是一个长度为奇数的回文串。Copa 害怕忘记密码,所以他决定把密码写在一张纸上。他发现这样保存密码不安全,于是他决定按下述方法加密密码:他选定一个整数 X ,保证 X 不小于 0 ,且 2X 严格小于串长度。然后他把密码分成 3 段,最前面的 X 个字符为一段,最后面的 X 个字符为一段,剩余的字符为一段。不妨把这三段依次原创 2022-01-21 11:33:54 · 503 阅读 · 0 评论 -
扩展kmp算法总结
扩展kmp是用来处理这样一类问题的:有一个文本串S,一个模式串T,求对于S串每一个后缀与T串的最长公共前缀。这个算法的时间复杂度和kmp一样,都是O(n)的。最终答案保存于extend[i]中,extend[i]表示S串从i开始的后缀与T串最长公共前缀长度。如果遍历extend数组,统计extend[i]等于strlen(T)的出现次数,那它就实现了kmp的功能,因此称其为扩展kmp算法。以P5410 【模板】扩展 KMP(Z 函数) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)这道原创 2021-10-06 14:43:19 · 386 阅读 · 0 评论 -
[好题][二分][字符串哈希]Checking the Text POJ2758
Wind's birthday is approaching. In order to buy a really really fantastic gift for her, Jiajia has to take a boring yet money-making job - a text checker.This job is very humdrum. Jiajia will be given a string of text what is English letters and he must c原创 2021-10-25 12:03:11 · 194 阅读 · 0 评论 -
[n串的最长公共子串][后缀数组]Corporate Identity POJ3450
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includes company logo but also other signs, like trademarks. One of such companies is Internet Building Masters (IBM), which has recently asked ACM for a help wit原创 2021-10-24 19:55:50 · 195 阅读 · 0 评论 -
[最长回文后缀][后缀数组]Extend to Palindrome UVA11475
Your task is, given an integer N, to make a palidrome (word that reads the same when you reverse it) of length at least N. Any palindrome will do. Easy, isn’t it? That’s what you thought before you passed it on to your inexperienced team-mate. When the con原创 2021-10-24 08:59:53 · 267 阅读 · 0 评论 -
[二分][后缀数组]Substrings POJ1226
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.InputThe first line of the input contains a single integer原创 2021-10-23 20:09:46 · 122 阅读 · 0 评论 -
[二分][后缀数组]Finding Palindromes POJ3376
You are the King of Byteland. Your agents have just intercepted a batch of encrypted enemy messages concerning the date of the planned attack on your island. You immedietaly send for the Bytelandian Cryptographer, but he is currently busy eating popcorn an原创 2021-10-23 19:09:10 · 91 阅读 · 0 评论 -
[二分][后缀数组]Life Forms POJ3294
You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial traits such as height, colour, wrinkles, ears, eyebrows and the like. A few bear no human resemblance; these typically have geometric or amorphous shapes l原创 2021-10-23 11:44:04 · 127 阅读 · 0 评论 -
[究极好题][rmq][后缀数组]Maximum repetition substring POJ3693
The repetition number of a string is defined as the maximum numberRsuch that the string can be partitioned intoRsame consecutive substrings. For example, the repetition number of "ababab" is 3 and "ababa" is 1.Given a string containing lowercase lett...原创 2021-10-22 16:33:23 · 137 阅读 · 0 评论 -
[后缀数组][最长公共子串]Long Long Message POJ2774
The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days: his mother is getting ill. Being worried about spending so much on railway tickets (Byterland is such a big country, and he has to spend 16 shou原创 2021-10-20 17:14:23 · 155 阅读 · 0 评论 -
(含证明)后缀数组之height数组应用
相信做过几道后缀数组题的人都深有体会,求出来的sa、rank数组用处不大,真正有用的是height数组。下面总结一下目前遇到的height数组的用法。1. 求字符串两后缀最长公共前缀 求后缀i与后缀j的最长公共前缀长度,也就是min(height[rank[i]+1], height[rank[i]+2, ......, height[rank[j]]),假设rank[i] < rank[j]的情况下。只需要证明出传递性就得证,传递性为:如果有三个字符串, 按字典序排序,lcp(...原创 2021-10-20 15:53:25 · 407 阅读 · 0 评论 -
[好题][height][后缀数组]New Distinct Substrings SPOJ SUBST1
Given a string, we need to find the total number of its distinct substrings.InputT- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000OutputFor each test case output one number saying the number of di原创 2021-10-19 21:01:45 · 181 阅读 · 0 评论 -
[二分][后缀数组]Milk Patterns POJ3261
Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are some regular patterns in the daily mil原创 2021-10-19 19:32:47 · 126 阅读 · 0 评论 -
[二分][后缀数组]Musical Theme POJ1743
A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the piano. It is unfortunate but true that this representation of melodies ignores the notion of musical timing; bu原创 2021-10-19 18:55:10 · 113 阅读 · 0 评论 -
后缀数组总结
后缀数组(suffix array)是解决字符串问题非常有力的工具,主要是为了得到三个数组,分别是sa[i],rank[i],height[i]。先对字符串的各后缀进行排序,sa[i]表示排序后第i名的后缀它开始的位置,rank[i]表示从i这个位置往后的后缀它的排名是多少,显然sa和rank数组互逆,如果已知sa[i] = t,则rank[t] = i,height[i]表示排完序后第i个后缀和第i-1个后缀的lcp(最长公共前缀)长度。具体算法实现大致可分为两类,一种是基于倍增+基数排序的思想,复杂原创 2021-10-19 15:24:12 · 158 阅读 · 0 评论 -
AC自动机(加强版)洛谷P3796
题目描述有NN个由小写字母组成的模式串以及一个文本串TT。每个模式串可能会在文本串中出现多次。你需要找出哪些模式串在文本串TT中出现的次数最多。输入格式输入含多组数据。保证输入数据不超过5050组。每组数据的第一行为一个正整数NN,表示共有NN个模式串,1 \leq N \leq 1501≤N≤150。接下去NN行,每行一个长度小于等于7070的模式串。下一行是一个长度小于等于10^6106的文本串TT。保证不存在两个相同的模式串。输入结束标志为N...原创 2021-10-08 21:06:19 · 258 阅读 · 0 评论 -
[ac自动机]病毒侵袭持续中 HDU3065
小t非常感谢大家帮忙解决了他的上一个问题。然而病毒侵袭持续中。在小t的不懈努力下,他发现了网路中的“万恶之源”。这是一个庞大的病毒网站,他有着好多好多的病毒,但是这个网站包含的病毒很奇怪,这些病毒的特征码很短,而且只包含“英文大写字符”。当然小t好想好想为民除害,但是小t从来不打没有准备的战争。知己知彼,百战不殆,小t首先要做的是知道这个病毒网站特征:包含多少不同的病毒,每种病毒出现了多少次。大家能再帮帮他吗?Input第一行,一个整数N(1<=N<=1000),表示病毒特征码的个数。原创 2021-10-08 16:24:01 · 98 阅读 · 0 评论 -
[ac自动机]病毒侵袭 HDU2896
当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻。。。。在这样的时刻,人们却异常兴奋――我们能在有生之年看到500年一遇的世界奇观,那是多么幸福的事儿啊~~但网路上总有那么些网站,开始借着民众的好奇心,打着介绍日食的旗号,大肆传播病毒。小t不幸成为受害者之一。小t如此生气,他决定要把世界上所有带病毒的网站都找出来。当然,谁都知道这是不可能的。小t却执意要完成这不能的任务,他说:“子子孙孙无穷匮也!”(愚公后继有人了)。万事开头难,小t收集了好多病毒的特征码,又收集了一批诡异网站的源码,他原创 2021-10-08 16:15:29 · 92 阅读 · 0 评论 -
[ac自动机]Keywords Search HDU2222
In the modern time, Search engine came into the life of everybody like Google, Baidu, etc.Wiskey also wants to bring this feature to his image retrieval system.Every image have a long description, when users type some keywords to find the image, the syst原创 2021-10-08 16:03:29 · 118 阅读 · 0 评论 -
AC自动机算法总结
前言:类似kmp,ac自动机也是个字符串匹配算法,不过kmp只能单模式串与文本串的匹配,ac自动机可以实现多模式串与文本串的匹配。ac自动机需要两个前置知识点:kmp和trie。但实际上用到的只有trie罢了,感觉和kmp关系并不大,至少我记的模板是这样的。分三步: 1.构建trie树这部分就是普通的字典树插入操作,一模一样的。void insert(){ int now = 0, len = strlen(word); for(int i = 0; i <...原创 2021-10-08 15:55:21 · 303 阅读 · 0 评论