`
Coco_young
  • 浏览: 120366 次
  • 性别: Icon_minigender_1
  • 来自: 湖南长沙
社区版块
存档分类
最新评论
文章列表
传送门:http://poj.org/problem?id=3080 题目大意:给定M个字符串(2<=M<=10),长度不超过60个字符,要求求出他们的最长公共子串,如果存在多个解,输出字典序最小的,如果该子串长度小于3,输出no ....(见题目描述) 思路:枚举某一个字符串的所有子串,拿去和剩余的所有字符串匹配,保存长度最大且字典序最小的即可,无所谓用KMP,暴力就行了,算法的主要时间花在枚举子串上面,这里为了练习KMP还是写了个KMP的匹配. 代码: #include<iostream> #include<cstring> #include ...
传送门:http://poj.org/problem?id=2752 题目描述:要求求出字符串S所有满足如下条件的子串长度(1.子串T为S的前缀 2.子串T为S的后缀)。 解题思路:利用KMP的NEXT数组的特性,Next[pos]的含义是在pos处失配时pos应该指向的下一个位置,那么0-(Next[pos]-1)构成的字符串和(pos-Next[pos])-(pos-1)构成的字符串是相同么,那么即0-(Next[pos]-1)构成的字符串是,0-pos-1构成的字符串的前缀后缀子串,这样,考虑在主串S后面增加一个字符,构成新字符串P,那么求出P最后一个位置的Next[]值,那么就可以按 ...
传送门:http://poj.org/problem?id=3461 题目大意:给定一个主串和一个模式,求模式在主串中出现的次数。 解题思路:直接修改标准KMP函数,当匹配成功是不是跳出循环,而是直接按最后一个字符失配的情况去滑动模式串,以获取下一个可能出现的匹配。 代码: #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int MAXN = 1000010,MAXM = 10010; char T[MAXN],P[MAXM]; in ...
传送门:http://poj.org/problem?id=2406 题意:给定一个字符串,让你求出他最多由几个相同的连续子串连接而成。 思路:求出这个字符串的最小周期,然后用总长度/最小周期长度即是解。 关于如何求最小周期:这里YY了一个方法,就是把该字符串增长一倍,然后拿原来的字符串做模式,增长后的字符串做主串,用KMP求模式在主串第1个位置(下标为0,包含第一个位置)之后的第一个匹配位置,就是最小周期长度。(如何证明当然不会啦。。。。。仅仅是YY出来的,没想到AC了。) 代码: #include<iostream> #include<cstdio> #in ...
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题意:裸的模式匹配问题,N值较大,必须使用线性算法,考虑上KMP。 关于KMP: 好久之前就看过KMP不过一直没搞懂,最近要搞下字符串,所以先拿它开刀,翻看了严蔚敏老师的数据结构,研究了许久,算是对KMP略知一二了吧,其KMP主算法还是比较好理解来的(不回溯主串匹配指针,当失配时,利用已经匹配的部分串的信息,使模式串指针向前移动,然后继续匹配),关键在于NEXT数组的求法,其实也不算很难理解(一个递推关系+自匹配的过程),书上后面说的那个修正NEXT数组的求法也比较好理解(当P[i]=P[ ...
1093 - Ghajini PDF (English) Statistics Forum Time Limit:1 second(s) Memory Limit:32 MB Amir is having a short term memory problem. He can't remember anything for more thandmilliseconds. Amir is playing a game named 'Find Max Difference'. The game is actually designed for chi ...
题目描述: Givennsegments (1 dimensional) andqpoints, for each point you have to find the number of segments which contain that point. A pointpiwill lie in a segmentA BifA ≤ pi≤ B. For example, if the segments are(6 12), (8 8), (10 12), (8 11), (0 12)and the point is11, then it is contained by4segment ...
1087 - Diablo PDF (English) Statistics Forum Time Limit:2 second(s) Memory Limit:64 MB All of you must have played the game 'Diablo'. It's an exclusive game to play. In this game the main opponent of you is Diablo. If you kill him the game finishes. But as usual, Diablo is sma ...
转载自:http://hi.baidu.com/%C4%CE%CF%A3nice/blog/item/d24c1202d20dc0e509fa934e.html PDF文件的官方阅读程序“Adobe Acrobat Reader”不支持自定义“书签”<nobr style="line-height:18.99pt; color:rgb(102,0,255); border-bottom-color:rgb(102,0,255); border-bottom-width:1px; bo ...
转载自:http://hi.baidu.com/horse789/blog/item/2413d222f3ba604093580721.html MSDN for VC6.0 简体中文版下载 2010-09-07 15:07 MSDN CD1: ed2k://|file|%5BMicrosoft.Visual.Studio6.0.MSDN.Library%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%E7%89%88%5D.MSDN60CHSCD1.iso|592472064|E834C35CB1773A7347FF ...
Prime Palindromes The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (5 <= a < b <= 100,000,000); ...
Packing Rectangles IOI 95 The six basic layouts of four rectangles Four rectangles are given. Find the smallest enclosing (new) rectangle into which these four may be fitted without overlapping. By smallest rectangle, we mean the one with the smallest area. All four rectangles should have th ...
该模板来自于吉林大学ACM模板库 #include<iostream> using namespace std; const int base = 10000; const int width = 4; const int N = 1000; struct bint{ int ln,v[N]; bint(int r=0){ for(ln = 0;r>0;r/=base)v[ln++] = r%base; } bint operator = (const bint &r){ memcpy(this,& ...
昨天去图书馆借了一本C++代码风格的书,稍微浏览了一下,上面讲了很多写代码的基本原则。 于是,拿自己现在写的代码和以前写的代码比较了一下下,发现以前的是非常非常猥琐,现在的是非常猥琐。 嗯,说明还是有进步的,本人还能救。
题意:裸的平衡树题 平衡树功能:插入,删除最大,删除最小 挂一个SBT模板吧,明天就校赛了,所以重写了一下SBT,把原来的删除操作改了下: #include<iostream> #include<cstdio> using namespace std; const int MAXN = 1111111,INF = 10000001; struct Key{ int k,p; Key(){} Key(int kk,int pp):k(kk),p(pp){} bool operator < (const Key &ke) ...
Global site tag (gtag.js) - Google Analytics