hdu3518 Boring counting】的更多相关文章

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=3518 题目: Boring counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3187    Accepted Submission(s): 1320 Problem Description 035 now faced…
Boring counting 题目传送门 解题思路 后缀数组.枚举每种长度,对于每个字符串,记录其最大起始位置和最小起始位置,比较是否重合. 代码如下 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; const int N = 1005; char s[N]; int sa[N], x[N], y[N], c[N]; int n, m; void get_sa…
裸的统计不同的重复出现子串(不重叠)种数的题.多次使用后缀排序要注意小细节.y数组在重复使用时一定要清空,看那个line25 +k就明白了 ,cnt也要清空,为什么就不说了 #include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T>inline ):;} template<typename T>inline ):;} +; char s[N]; int n…
传送门 求出现超过1次的不重叠子串的个数 根据论文中的方法. 枚举子串的长度 k. 用 k 给 height 数组分组,每一组求解,看看当前组的位置最靠后的后缀和位置最靠前的后缀所差个数是否大于长度,大于的话 ans++. 分组思想需要认真体会一下. ——代码 #include <cstdio> #include <cstring> #include <iostream> #define N 1005 #define max(x, y) ((x) > (y) ?…
Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a list of queries, for each…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submission(s): 2811    Accepted Submission(s): 827 Problem Description In this problem we consider a rooted tree with N vertices. The vertices a…
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2610 Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith ele…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Problem Description In this problem we consider a rooted tree with N vertices. The vertices are numbered from 1 to N, and vertex 1 represents the root…
Boring counting Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3518 Mean: 给你一个字符串,求:至少出现了两次(无重叠)的子串的种类数. analyse: 后缀数组中height数组的运用,一般这个数组用得很少. 总体思路:分组统计的思想:将相同前缀的后缀分在一个组,然后对于1到len/2的每一个固定长度进行统计ans. 首先我们先求一遍后缀数组,并把height数组求出来.height数组代表的含…
Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Description     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a…
Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Problem Description In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now yo…
http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3237 Problem H:Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 8  Solved: 4 [Submit][Status][Discuss] Description In this problem you are given a number sequence P consisting of N int…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 2224: Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MB Description In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence.…
SAM基本操作 拓扑寻求每个节点  最左边的出现left,最右边的出现right,已经有几个num ...... 对于每个出现两次以上的节点.对其所相应的一串子串的长度范围 [fa->len+1,len] 和其最大间距 right-left比較 就可以...... Boring counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(…
题目:Boring counting 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3518 题意:给一个字符串,问有多少子串出现过两次以上,重叠不能算两次,比如ababa,aba只出现一次. 思路: 网上搜的题解估计大部分都是后缀数组,但字典树+优化是可以解决该问题的. 字典树解决这题难点就是内存,先不考虑内存,那么可以遍历起始点,然后添加入字典树,比如现在abab要添加进字典树,如果原本已经存在abab,并且两个不重叠,那么ans++,同时将aba…
http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3237 Problem H:Boring Counting Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 6  Solved: 2[Submit][Status][Discuss] Description In this problem you are given a number sequence P consisting of N integ…
Boring counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2253    Accepted Submission(s): 924 Problem Description 035 now faced a tough problem,his english teacher gives him a string,whic…
Boring counting: http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意: 求一棵树上,每个节点的子节点中,同一颜色出现k次 的 个数. 思路: 由于是子树中出现了k次,sum+1.所以增加某种颜色的时候,如果这个颜色+1==k,那么sum++.如果删除的时候这个数+1 == k+1,那么sum--: #include <algorithm> #include <iterator> #include <iostrea…
Boring counting \[ Time Limit: 1000 ms \quad Memory Limit: 32768 kB \] 题意 给出一个字符串,求出其中出现两次及以上的子串个数,要求子串之间不可以重合. 思路 对字符串后缀数组,然后枚举子串长度 \(len\),若某一段连续的 \(sa[i]\) 的 \(lcp \geq len\),那么说明这一段内存在一个长度为 \(lcp\) 的子串,而我们只需要其中的前 \(len\) 部分,接下来只要找出这个子串出现的最左和最右位置,…
Boring counting \[ Time Limit: 1000 ms \quad Memory Limit: 32768 kB \] 题意 给出一个字符串,求出其中出现两次及以上的子串个数,要求子串之间不可以重合. 思路 在 \(SAM\) 上对于节点 \(i\) ,其包含的子串长度范围为 \(\left[maxlen\left(father\right)+1,maxlen\left(i\right) \right]\),在考虑节点\(i\)的 \(endpos\),设出现的最左位置为…
Boring counting Problem Description In this problem we consider a rooted tree with N vertices. The vertices are numbered from 1 to N, and vertex 1 represents the root. There are integer weights on each vectice. Your task is to answer a list of querie…
题意:找出一个字符串中至少重复出现两次的字串的个数(重复出现时不能重叠). 后缀数组 枚举字串长度h,对于每一次的h,利用height数组,找出连续的height大于等于h的里面最左端和最右端得为之l和r.如果l+h-1<r的话,说明没有重叠,答案加1. #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> using…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2549    Accepted Submission(s): 1030 Problem Description 035 now faced a tough problem,his english teacher gives him a string,which consists with…
题目 参考自:http://blog.sina.com.cn/s/blog_64675f540100k9el.html 题目描述: 找出一个字符串中至少重复出现两次的字串的个数(重复出现时不能重叠). 解题报告: 后缀数组即可解之. 枚举字串长度h 对于每一次的h,利用height数组,找出连续的height大于等于h的里面最左端和最右端得为之l和r. 如果l + h - 1 < r的话,说明没有重叠,答案加1. O(n^2)复杂度. #include<stdio.h> #include…
题目链接:http://acm.upc.edu.cn/problem.php?id=2224 题意:给出n个数pi,和m个查询,每个查询给出l,r,a,b,让你求在区间l~r之间的pi的个数(A<=pi<=B,l<=i<=r). 参考链接:http://www.cnblogs.com/zj62/p/3558967.html #include <iostream> #include <cstdio> #include <cstring> #incl…
研究了整整一天orz……直接上官方题解神思路 #include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; ; struct node { int v, next; }; struct subTree { int st, ed; }; struct Queryy { int i;…
题目链接 题意:给定长度为n(n <= 1000)的只含小写字母的字符串,问字符串子串不重叠出现最少两次的不同子串个数; input: aaaa ababcabb aaaaaa # output 2 3 3   思路:套用后缀数组求解出sa数组和height数组,之后枚举后缀的公共前缀长度i,由于不能重叠,所以计数的是相邻height不满足LCP >= i的. 写写对后缀数组倍增算法的理解: 1.如果要sa数组对应的值也是1~n就需要在最后加上一个最小的且不出现的字符'#',里面y[]是利用s…
基本思路是将树形结构转线性结构,因为查询的是从任意结点到叶子结点的路径.从而将每个查询转换成区间,表示从该结点到叶子结点的路径.离线做,按照右边界升序排序.利用树状数组区间修改.树状数组表示有K个数据的数量,利用pos进行维护.假设现有的sz >= K, 那么需要对区间进行修改. /* 4358 */ #include <iostream> #include <sstream> #include <string> #include <map> #inc…
[题意]给定一个长度为N的数列,M个询问区间[L,R]内大于等于A小于等于B的数的个数. [题目链接]http://acm.upc.edu.cn/problem.php?id=2224 省赛的时候脑抽想了10min没想出来就看别的题去了= =,赛后又想了10min想出来了并且1Y...真嫌弃自己= =... [分析]如果做过询问区间[L,R]内小于H的个数的那道线段树题(HDU 4417 2012年杭州赛区网络赛)那么这题就好想了.那在这里再说一下做法:{将所有的询问离线读入之后,按H从小到大排…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意:以1为根节点含有N(N <= 1e5)个结点的树,每个节点有一个权值(weight <= 1e9).之后有m(m <= 1e5)次查询,每次查询以节点u为子树的树中,权值出现k次的权值有多少个? Sample Input 1 3 1 (n,k) 1 2 2 1 2 1 3 3 (m) 2 1 3   Sample Output Case #1: 1 1 1   思路:建好树之后,…