hdu 5510 Bazinga KMP+尺取法】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标(从1开始)j,使得存在i < j使得s[i]不是s[j]的子串: 思路:KMP很容易想到,因为Trie是处理前缀串的,不能处理子串.在KMP中,还要优化下,就是父串可以代表子串,并且直接递推处理(用尺取法,每次处理没有父串的串)即可: #include<bits/stdc++.h> usin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 思路: 一开始直接用KMP莽了发,超时了,后面发现如果前面的字符串被后面的字符串包含,那么我们就不需要用前面的字符串去比较了,把他标记掉就好了. 实现代码: #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; ][];…
废话: 这道题很是花了我一番功夫.首先,我不会kmp算法,还专门学了一下这个算法.其次,即使会用kmp,但是如果暴力枚举的话,还是毫无疑问会爆掉.因此在dfs的基础上加上两次剪枝解决了这道题. 题意: 我没有读题,只是队友给我解释了题意,然后我根据题意写的题. 大概意思是给n个字符串,从上到下依次标记为1——n,寻找一个标记最大的串,要求这个串满足:标记比它小的串中至少有一个不是它的子串. 输入: 第一行输入一个整型t,表示共有t组数据. 每组数据首行一个整型n,表示有n个串. 接下来n行,每行…
题意: 给\(n(1 \leq n \leq 500)\)个字符串,求一个最大的\(i\),使得存在一个\(S_{j}\)不是\(S_i\)的子串. 分析: 维护两个指针\(l,r\) 那么有两种情况: 如果\(S_l\)是\(S_r\)的子串,那么\(l\)++. 如果\(S_l\)不是是\(S_r\)的子串,那么将答案更新为\(r\),然后\(r\)++. 考虑\(S_{r+1}\)的时候为什么同样不考虑\(S_l\)之前的串了呢? 因为\(S_l\)之前的串都是后面某个串的子串,所以如果他…
Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2287    Accepted Submission(s): 713 Problem Description Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious.For…
Bazinga HDU 5510 Bazinga(双指针) 题链 解法:对于串i来说,如果串i是不符合的,那么代表串i之前的字符串都是i的子串,那么我们求一个新的i(定义为ti),如果i是ti 的子串,那么串i之前的字符串都没必要再匹配了,如果不是,ti就是符合要求的答案之一 #include <cstdio> #include <iostream> #include <cstring> using namespace std; const int N=2005; ch…
http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选的子串的最大长度. 思路: 由于这两个子串是互不重叠的,那么这两个子串之间的间隔可以是奇数也可以是偶数,针对这两种情况我们枚举中心点,然后尺取法处理,具体看代码就懂了. #include<iostream> #include<algorithm> #include<cstring…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5672 题意: 有一个10≤长度≤1,000,000的字符串,仅由小写字母构成.求有多少个子串,包含有至少k(1≤k≤26)个不同的字母? 分析: 很典型的尺取法. 不断依次移动区间的头尾,使区间满足条件,并找到这样的区间个数. 注意说的是包含至少k个,所以只要找到正好包含k个的区间,然后加上包含后面的串的个数就好了. 代码: #include<cstdio> #include<cstrin…
Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 Description Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious.For n given strings S1,S2,⋯,Sn, labelled from 1 to n, you…
2015沈阳区域赛现场赛第2题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:给定一个由字符串组成的序列,一共n个元素,每个元素是一个不超过2000个字符的字符串.求"存在秩小于 i 且不是 i 的子串"的最大的 i (1<= i <= n). 数据范围:n [1, 500],T组输入,T [1, 50] 思路:从1到n-1枚举每个字符串str[i],判断是否有 j < i 使得str[j]不是str[i…
http://acm.hdu.edu.cn/showproblem.php?pid=5510 Problem Description: Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious.For n given strings S1,S2,⋯,Sn, labelled from 1 to n, you should find the largest i (1≤i≤n) such that t…
Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 214    Accepted Submission(s): 89 Problem Description Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious.For n…
题目:传送门. 题意:t 组数据,每组 n 个串,对于第 i 个串如果存在 1 到 i-1 中的某个串不是 i 的子串,那么这个第 i 个串符合题意,求 i 的最大值. 题解:KMP,AC自动机也可以,直接匹配就行.注意如果串 j 是j+1的子串,那么对于j+2来说只需要匹配j+1是不是他的子串即可,因为比匹配 j 更容易符合题意.用cin会超时,要用scanf. #include <iostream> #include <cstdio> #include <cmath>…
题目链接: Hdu 5358 First One 题目描述: 数组a有n个元素,S[i,j]定义为a[i]+a[i+1]+.....+a[j],问:这个死东西等于多少? 解题思路: 二分肯定超,这个题目的时间卡的炒鸡严格,只有n*log(n)的复杂度才能过,n*log(n)^2都不可以的. 只需要枚举K,并且枚举区间左端i值,计算K的贡献值,然后遍历时候计算一下常数相加即可. #include <cstdio> #include <cstring> #include <ios…
Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2078    Accepted Submission(s): 642 Problem Description  to n, you should find the largest i (1≤i≤n) such that there exists an integer j (…
Problem Description Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious. For n given strings S1,S2,⋯,Sn, labelled to n, you should find the largest i (≤i≤n) such that there exists an integer j (≤j<i) and Sj is not a substr…
http://acm.hdu.edu.cn/showproblem.php?pid=5510 Bazinga Problem Description   Ladies and gentlemen, please sit up straight.Don't tilt your head. I'm serious.For n given strings S1,S2,⋯,Sn, labelled from 1 to n, you should find the largest i (1≤i≤n) su…
小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1572    Accepted Submission(s): 513 Problem Description 度度熊喜欢着喵哈哈村的大明星——星星小姐. 为什么度度熊会喜欢星星小姐呢? 首先星星小姐笑起来非常动人,其次星星小姐唱歌也非常好听. 但这都不是最重要的,最重要的是…
题意:给一个数列,按如下公式求和. 分析:场上做的时候,傻傻以为是线段树,也没想出题者为啥出log2,就是S(i,j) 的二进制表示的位数.只能说我做题依旧太死板,让求和就按规矩求和,多考虑一下就能发现这个题目应该是另想办法解决的,类似于改代码的题目,直接告诉你C++代码,让你从TLE改成AC,其实真正让你改的是算法,全身都要变. 看了题解,终于明白这道题目的正解算法: 因为S(i,j)的位数在一定范围内是一样的,所以我们可以枚举位数1~35(顶多是2^34),怎么计算(i+j)?继续枚举起点k…
题意:告诉一张带权图,不存在环,存下每个点能够到的最大的距离,就是一个长度为n的序列,然后求出最大值-最小值不大于Q的最长子序列的长度. 做法1:两步,第一步是根据图计算出这个序列,大姐头用了树形DP(并不懂DP),然后就是求子序列长度,其实完全可以用RMQ爆,但是大姐头觉得会超时,于是就采用维护最大,最小值(差超过Q的时候就删掉,然后记录长度). 做法2:通过3次bfs求树的直径(为什么啊),然后RMQ求出所有区间的最大最小值 时间复杂度:290ms #include <cstdio> #i…
Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K as following rules: Initially, the array B is empty. Consider each interval in array A. If the length of this interval is less than K, then ignore th…
String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There is a string S.S only contain lower case English character.(10≤length(S)≤1,000,000)How many substrings there are that contain at least…
题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Claris280MS秒过.......%%% #include <stdio.h> #include <stdlib.h> #include <cmath> #include <string.h> #include <iostream> #include…
题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B=∑i=0n−1|Ai−Bn−1−i| The difference between the two characters is defined as the difference in ASCII. You should find the maximum length of two non-over…
We define the distance of two strings A and B with same length n is dis A,B =∑ i=0 n−1 |A i −B n−1−i | disA,B=∑i=0n−1|Ai−Bn−1−i| The difference between the two characters is defined as the difference in ASCII. You should find the maximum length of tw…
Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 932    Accepted Submission(s): 382 Problem Description You are given a string S consisting of lowercase letters, and your task is cou…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22876   Accepted: 12509 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
String Problem Description There is a string S.S only contain lower case English character.(10≤length(S)≤1,000,000)How many substrings there are that contain at least k(1≤k≤26) distinct characters?   Input There are multiple test cases. The first lin…
题意:给你一个序列,求最长的两段回文子串,要求他们共用中间的一半. 思路:利用Manacher求出p[i]表示的当前位置的最长回文串长度,然后把每一个长度大于等于2的回文串的左区间和右区间分别放到两个数组里面,由于做manacher时添加了特殊的数字,所以处理的时候稍微注意一下. 然后把左右区间按照左端点排序,接着根据尺取法来找答案中的那一段重合的部分.对于每一段右区间R[i]而言,只有L[j].right<=R[i].right && L[j].left<=R[i].righ…
多校的题,摆明了数学题,但是没想出来,蠢爆了,之前算了半天的s[i][j]的和,其实是积.其实比赛的时候我连log(s[i][j])+1是s[i][j]的位数都没看出来,说出来都丢人. 知道了这个之后,就枚举二进制数的每一位,因为元素都是非负数,所以sum数组是非降的,这里用到了尺取法,之前也是听说过,应该是做过吧,不太记得了. 因为[2k-1,2k)的位数是k,枚举时,固定左端点,在sum数组找到最小的大于等于2k-1,最大的小于2k的点,这中间的点和左端点的s[i][j]就对于当前的k满足条…