
ACM-数据结构
文章平均质量分 50
__proto__
学参天地,德合自然
展开
-
树的直径模板
#include #include #include using namespace std;const int maxn = 10005;struct D{ int to,v;};vector V[maxn];int vis[maxn];int s;int dfs(int n,int length){ static int dis = length;原创 2016-10-19 16:57:21 · 274 阅读 · 0 评论 -
HDU5927
#include using namespace std;const int maxn = 1e5+10;vector V[maxn];struct Node{ int node; int father; int deep; Node(){ node = father = deep = 0; }}N[maxn],Un[maxn原创 2016-10-07 21:00:25 · 271 阅读 · 0 评论 -
2016北京网络赛C hihocoder
个人觉得就是考察STL#include using namespace std;const int maxn = 550;char save[maxn];string S[maxn];int Scount=0;char Str[maxn];mapMap;stringstream stream;int cmp(const string &str1,const string &原创 2016-09-24 15:58:25 · 512 阅读 · 0 评论 -
AC自动机模板
用 HDU2222 这题作为模板原创 2016-09-22 07:11:08 · 268 阅读 · 0 评论 -
ZOJ3587 Marlon's String KMP技巧处理
题意:给定一个 T 串,一个 S 串,问由 S 串中的两个子串组成 T 串有多少种方式?思路:这道题让我搞了好久,举个例子,将T串分成任意两段,那么必然是从中间断开的,即我们就需要在S中寻找和T的前半段匹配的子串数量,记录在V1数组中,和T的后半段匹配的子串的数量,记录在V2数组中,最后求出 V1[1]*V2[strlen(T)-1]+V1[2]*V2[strlen(T)-2]+……+V1[strl原创 2016-03-26 14:10:22 · 395 阅读 · 0 评论 -
HDU3746 Cyclic Nacklace KMP找循环节
题意:给你一个字符串,让你求这个字符串变成一个循环节的字符串最少需要添加的字符数目。思路:说白了就是通过next数组寻找循环节,直接上代码,求循环节部分很显然。代码如下:#include <bits/stdc++.h>using namespace std;const int maxn=1e5+5;char p[maxn];int NEXT[maxn];void get_NEXT(){原创 2016-03-26 13:59:24 · 340 阅读 · 0 评论 -
HDU2594 Simpsons’ Hidden Talents KMP
题意:给你两个字符串,问你第一个字符串前缀和第二个字符串的后缀最长匹配长度是多少?思路: 简单的next数组的理解, 连接两字符串,在连接处加一个无关字符,如‘*’,这样做是为了保证不会出现连接后前后缀最大匹配值大于某个字符串的情况,然后直接输出next[strlen(str)]以及其前缀即可。代码如下:#include <bits/stdc++.h>using namespace std;cons原创 2016-03-26 13:52:55 · 348 阅读 · 0 评论 -
HDU4763 Theme Section KMP-next应用
题意:给你一个字符串,若将它分割成 AXAXA 的形式,A最长是多少?思路:对于这道题我看了很多题解,但感觉讲的还是很模糊,这道题从next数组入手即可,很短的代码便可搞定,主要要了解一点如果给你一个长度为n的字符串,那么前后缀的最大匹配值自然是next[n],那么次长前后缀匹配值是什么呢? 其实就是next[ next[n] ] ,我们可以通过找出前后缀的匹配值然后知道中间子串的上下界,然后再这个原创 2016-03-26 13:24:06 · 322 阅读 · 0 评论 -
HDU3336 Count the string KMP+递推
题意:T组测试数据,给你一个字符串,求其前缀出现过的次数之和。例如 : abab 前缀 a 出现过两次,前缀 ab 出现过两次,前缀 aba 出现过一次,前缀 abab 出现过一次,所有前缀和为 6 ,故输出6。思路:本题的重点在于对 next 数组的理解上,next 表示了在第 i 个字符时能匹配的最长前缀,更多关于 next 数组的含义请参考 KMP算法 的解析。对于这道题,我们只需要记录一下原创 2016-03-26 12:28:53 · 290 阅读 · 0 评论 -
poj 2823 滑动窗口 单调队列
DescriptionAn array of size n ≤ 10 6 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the原创 2016-03-20 16:20:39 · 558 阅读 · 0 评论 -
poj 2352 树状数组
DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that ar原创 2016-03-20 15:59:54 · 221 阅读 · 0 评论 -
poj 2528 离散化+线段树
DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city coun原创 2016-03-20 15:47:24 · 257 阅读 · 0 评论 -
POJ 2299 线段树/树状数组求逆序数
题意: 给你一组无序数 (小于等于500,000) ,让你通过相邻两数的交换,使其变成升序排列。(这些数两两都是不同的)。刚拿到这道题的时候,不知道该如何下手,后来经过一位善良美丽的学姐的启发,想到了用逆序数。 那么什么是逆序数呢 ? 这在线性代数中有提到过: 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序原创 2016-03-15 20:07:56 · 496 阅读 · 0 评论