随笔分类 - 字符串
摘要:题意:找出原串中出现超过2次的子串的数目,每个子串出现多次时不可重叠。分析:枚举子串的长度len,找到满足连续的height[i]>=len的最左端 l 和最右端的位置 r,如果r-l>=len说明子串没有重叠。View Code #include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;int N;char s[maxn];int sa[maxn],t[maxn],t2[maxn],c[maxn];void s
阅读全文
摘要:题意:给出长度为n的数字序列,求重复出现次数不小于k的最长序列(连续)的长度。例如序列 1 2 3 2 3 2 3 1,k=2,那么序列2 3 2 3重复出现了两次,长度为4。分析:二分枚举长度,如果在height数组中连续出现超过k次的话就满足。View Code #include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1000002;int s[maxn];int sa[maxn],t[maxn],t2[maxn],c[maxn
阅读全文
摘要:题意: 模拟手机的输入,手机每个按键负责一定数量的字符,知道了一些单词,和这些单词的使用频率,给出一个按键的顺序,问每个数字所在位置对应的最大可能的输入单词是哪个,如果找不到 输出‘MANUALLY‘分析:建立字典树,把单词存起来,并累加每个字母使用的频率,每出现输入的一个数字,找出那个数字上对应的字母所在位置频率最大的单词。#include<stdio.h>#include<string.h>#define clr(x)memset(x,0,sizeof(x))char res[105];char tmp[105];int la;struct node{ int co
阅读全文
摘要:题意: 给你两个字符串,让你找出第一个字符串的头部和第二个字符串尾部重合的部分,并尽可能的长,例如 aasdfs bdevaa 答案为 aa 2分析: 利用 KMP 算法得到的 next 函数的特点,把两字符串连到一起,找出头部和尾部重合的部分。View Code #include<stdio.h>#include<string.h>char s1[50005];char s2[50005];int next[100010];int len1,len2,len;void get(){ int i=0,j=-1; next[0]=-1; while(i<len) {
阅读全文
摘要:题意:给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数。分析: next 数组的巧用。View Code #include<stdio.h>#include<string.h>int next[100005];char b[100005];int len;void get(){ int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1||b[i]==b[j]) next[++i]=++j; else j=next[j]; }}int main(){ int ...
阅读全文
摘要:题意: 一个字符串,从头到某个位置,字符串的前缀最多重复了多少次。转一相关讲解:kmp next函数 kmp的周期问题,深入了解kmp中next的原理----------------------------------------------k m x j i由上,next【i】=j,两段红色的字符串相等(两个字符串完全相等),s[k....j]==s[m....i]设s[x...j]=s[j....i](xj=ji)则可得,以下简写字符串表达方式kj=kx+xj;mi=mj+ji;因为xj=ji,所以kx=mj,如下图所示------------- -----------...
阅读全文
摘要:DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message
阅读全文
摘要:Problem Description小t非常感谢大家帮忙解决了他的上一个问题。然而病毒侵袭持续中。在小t的不懈努力下,他发现了网路中的“万恶之源”。这是一个庞大的病毒网站,他有着好多好多的病毒,但是这个网站包含的病毒很奇怪,这些病毒的特征码很短,而且只包含“英文大写字符”。当然小t好想好想为民除害,但是小t从来不打没有准备的战争。知己知彼,百战不殆,小t首先要做的是知道这个病毒网站特征:包含多少不同的病毒,每种病毒出现了多少次。大家能再帮帮他吗?Input第一行,一个整数N(1<=N<=1000),表示病毒特征码的个数。接下来N行,每行表示一个病毒特征码,特征码字符串长度在1—5
阅读全文
摘要:Problem Description当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻。。。。在这样的时刻,人们却异常兴奋——我们能在有生之年看到500年一遇的世界奇观,那是多么幸福的事儿啊~~但网路上总有那么些网站,开始借着民众的好奇心,打着介绍日食的旗号,大肆传播病毒。小t不幸成为受害者之一。小t如此生气,他决定要把世界上所有带病毒的网站都找出来。当然,谁都知道这是不可能的。小t却执意要完成这不能的任务,他说:“子子孙孙无穷匮也!”(愚公后继有人了)。万事开头难,小t收集了好多病毒的特征码,又收集了一批诡异网站的源码,他想知道这些网站中哪些是有病毒的,又是带了怎样的病毒呢?
阅读全文
摘要:DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue listed these numbers:Emergency 911Alice 97 625 999Bob 91 12 54 26In this case, it's not possible to call Bob, because the central would
阅读全文
摘要:Problem Description我们大家经常用google检索信息,但是检索信息的程序是很困难编写的;现在请你编写一个简单的全文检索程序。问题的描述是这样的:给定一个信息流文件,信息完全有数字组成,数字个数不超过60000个,但也不少于60个;再给定一个关键字集合,其中关键字个数不超过10000个,每个关键字的信息数字不超过60个,但也不少于5个;两个不同的关键字的前4个数字是不相同的;由于流文件太长,已经把它分成多行;请你编写一个程序检索出有那些关键字在文件中出现过。Input第一行是两个整数M,N;M表示数字信息的行数,N表示关键字的个数;接着是M行信息数字,然后是一个空行;再接着是
阅读全文
摘要:Problem DescriptionIn the modern time, Search engine came into the life of everybody like Google, Baidu, etc.Wiskey also wants to bring this feature to his image retrieval system.Every image have a long description, when users type some keywords to find the image, the system will match the keywords
阅读全文
摘要:Problem DescriptionIn computer vision, a chain code is a sequence of numbers representing directions when following the contour of an object. For example, the following figure shows the contour represented by the chain code 22234446466001207560 (starting at the upper-left corner).Two chain codes may
阅读全文
摘要:Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每个提问都是一个字符串.注意:本题只有一组测试数据,处理到文件结束.Output对于每个提问,给出以该字符串为前缀的单词的数量Sample Inputbananabandbeeabsoluteacmba
阅读全文
摘要:DescriptionA prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that the empty string is not considered a prefix in
阅读全文
摘要:Problem DescriptionThe French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, puis surgissait l’inhumain
阅读全文
摘要:Problem Description一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。Sample Inputabcde a3aaaaaa aa#Sample Output
阅读全文
摘要:Problem DescriptionGiven two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2], ...... , a[K + M - 1] = b[M]. If there are more than one K exist, ou
阅读全文
摘要:Problem Description给定一个长度为偶数位的0,1字符串,请编程实现串的奇偶位互换。Input输入包含多组测试数据;输入的第一行是一个整数C,表示有C测试数据;接下来是C组测试数据,每组数据输入均为0,1字符串,保证串长为偶数位(串长<=50)。Output请为每组测试数据输出奇偶位互换后的结果;每组输出占一行。Sample Input201101100Sample Output10011100code:View Code #include<stdio.h>int main(){ int i,t; char s[51]; scanf("%d"
阅读全文


浙公网安备 33010602011771号