问题 给出一个长度为\(n\)的序列\(a[i]\),有\(m\)次询问, 每次给你一个\(k\),让你求一个最长子串\([l,r]\),使得\(max_l^r\{a_i\}-min_l^r\{a_i\}\leq k\) 思路一 我们显然可以看出这个长度是具有单调性的,于是我们二分答案 \(check\)的方式有以下几种 RMQ 需要\(nlogn\)的时间预处理,空间也要\(nlogn\) 预处理好最大和最小的\(st\)表,\(O(n)\)扫一遍即可 单调队列 时间空间都只需要\(O(n)\…
给定一个字符串,求它最长的回文子串长度,例如输入字符串'35534321',它的最长回文子串是'3553',所以返回4. 最容易想到的办法是枚举出所有的子串,然后一一判断是否为回文串,返回最长的回文子串长度.不用我说,枚举实现的耗时是我们无法忍受的.那么有没有高效查找回文子串的方法呢?答案当然是肯定的,那就是中心扩展法,选择一个元素作为中心,然后向外发散的寻找以该元素为圆心的最大回文子串.但是又出现了新的问题,回文子串的长度即可能是基数,也可能好是偶数,对于长度为偶数的回文子串来说是不存在中心元…
市面上最常见的魔方,是三阶魔方,英文名为Rubik's Cube,以魔方的发明者鲁比克教授的名字命名.另外,二阶魔方叫Pocket Cube,它只有2*2*2个角块,通常也就比较小:四阶魔方叫Revenge Cube,这是因为就算你好不容易复原了三阶魔方,四阶魔方也会向你“复仇”:而五阶魔方叫Professor Cube,人们认为只有专家才能够复原这么复杂的魔方. 作为ACM(A Cube Master),squee_spoon准备为九阶正十二面体魔方命名,此时他的脑中浮现出一个长长的字符串S,…
Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. Example 1: Input: s = "aaabb", k = 3 Output: 3 The longest substring is "aaa"…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T is "ece" which its length is 3. 给定一个字符串,找出包含最多k个不同字符的最长子字符串t的长度. 例如,给定s=“eceba”和k=2, T是…
点击这里查看原文 假设一个数组仅仅由1和-1组成,求该数组的和为0的最长子串的长度. 例如: {1,-1,1,-1,1,1,1} 输出:4. 昨天机试的时候做到这道题,不会做,今天思考一下. 普通的解法 枚举所有的子串,然后得到和为0的最长的长度,复杂度是O(n*n),这个应该会超时,昨天只能保存,不能运行,我猜这样应该不行,需要下面方法.其实看到这题,我想到的是最长回文子串这道题,仔细想想,还是挺像的,该搞一个传送门的. 正确的解法 解法:动态规划,dp0[i]表示以i结尾的加和为0 得到最长…
Life Forms   Description 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…
1297. Palindrome Time Limit: 1.0 secondMemory Limit: 16 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» s…
Language: Default Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 21228   Accepted: 8708 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes…
题目连接:hdu 3068 最长回文 解题思路:通过manachar算法求最长回文子串,如果用遍历的话绝对超时. #include <stdio.h> #include <string.h> const int N = 220005; int rad[N]; char string[N], tmpstr[N]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a &l…