2012年6月7日

hdu 2328 Corporate Identity

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2328题意:求多个字符串的最长公共子串,若有多个输出字典序最小。思路:先进行后缀数组操作。然后二分子串长度,根据height和sa数组的值,判断当前长度是否合适。当然,这里面还有hash映射的。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 910000;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],as[maxn],sa[max 阅读全文

posted @ 2012-06-07 21:01 aigoruan 阅读(157) 评论(0) 推荐(0)

hdu 1711 Number Sequence

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1711题意:给两个数字序列,判断第一个是否包含了第二个数列。思路一(正解):直接kmp;思路二(YY):求出第一个序列的前缀和,在第一个序列中取和第二个序列等长的子序列,如果这个子序列的和与第二个序列的和一样,才进行匹配算法。这个算法可以过不了一些特殊的数据。但在很短的时间内过了。View Code #include<stdio.h>#include<string.h>long long as[1000005],bs[10005],cs[1000005];int check(long 阅读全文

posted @ 2012-06-07 15:49 aigoruan 阅读(190) 评论(0) 推荐(0)

xmu 1337 后缀数组 + 暴力匹配

摘要: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1337题意:在一个串中求出一个长度为n的、重复了m次的子串(不能重叠)。思路:一直以为正解是后缀数组加其它高效的搜索方法。一水才知道,就是纯后缀数组+暴力匹配。先用后缀数组求出 sa,height两个数组的值,当height[i]=n时,取出当前子串,进行暴力匹配。囧~~~View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 101000;int wn[m 阅读全文

posted @ 2012-06-07 13:44 aigoruan 阅读(244) 评论(0) 推荐(0)

pku 1743

摘要: View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 20005;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],a[maxn],sa[maxn],rank[maxn],height[maxn];char r[maxn];int n;int Max(int x,int y){return x>y?x:y;}int Min(int x,int y){return x>y?y:x;}int cmp(int *r,i 阅读全文

posted @ 2012-06-07 12:05 aigoruan 阅读(163) 评论(0) 推荐(0)

hdu 1403 简单后缀数组应用

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1403题意:给两串字符,求最长的公共子串。仔细想下就会想到后缀数组了。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;const int maxn = 220005;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],a[maxn],sa[maxn],rank[maxn],height[maxn];char r[maxn];int 阅读全文

posted @ 2012-06-07 09:59 aigoruan 阅读(158) 评论(0) 推荐(0)

导航