字符串hash - POJ 3461 Oulipo】的更多相关文章

Oulipo Problem's Link ---------------------------------------------------------------------------- Mean: 给你一个模式串P和一个母串S,让你统计P串在S串中出现的次数. analyse: 一开始想到的就是使用KMP,就用KMP写了,93ms,挺快的. 我又用AC自动机写了一遍,万万没想到竟然超时了. 后来看别人有用字符串hash写的,于是又用字符串hash写了一遍,代码30+行,而且速度也挺快…
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] The 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: Tou…
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The 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…
题目链接 字符串hash判断字符串是否相等. code #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef unsigned long long uLL; ; uLL f[]; uLL Hash[]; ],b[]; int main () { int T; scanf("%d",&T); f[] = ; ; i<=; ++…
  E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3461 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a memb…
  E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3461 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a memb…
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 50450   Accepted: 20018 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a…
题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即可,当前匹配的字符数达到word字符串的长度,即可确定word字符串出现一次了. code: #include <cstdio> #include <cstring> using namespace std; ; ; char word[MAXM]; char text[MAXN];…
HDU题目 POJ题目 求目标串s中包含多少个模式串p KMP算法,必须好好利用next数组,, (kmp解析)——可参考 海子的博客  KMP算法 //写法一: #include<string> #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> using namespace std; void getNext(char *p,int…
Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Description The 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 quot…
Oulipo [题目链接]Oulipo [题目类型]KMP &题意: 给你两个字符串p和s,求出p在s中出现的次数. &题解: kmpC函数就是解题的,其中也就j=nex[j]难理解一些,j=nex[j]就代表对照的开始,如果j=nex[j]的值是4,就代表从第4个位置开始比较,正如这句话上面的那个j++,你都匹配上了,所以就会有j++,之后便会j大于等于匹配串的长度,这就代表找到了一个和匹配串一样的串,所以ans++,之后再去找该从哪个位置开始匹配 [时间复杂度]\(O(n+m)\) &…
Description The 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,…
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用后缀数组可以到0ms,但我不会XD. 暴力: #include<cstdio> #include<cstring> using namespace std; ][],ans[]; int main(){ int T,n; scanf("%d", &T); w…
传送门 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32373   Accepted: 13093 Description The 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…
题意:给出几组数据,每组有字符串W和T,问你W在T中出现几次. 思路:字符串长度很大,用KMP算法. 一开始写的是:调用KMP算法查找W在T中是否匹配,若匹配,则个数+1.则接下来T的索引移动相应的距离,再调用函数判断T接下来的序列中是否存在W. 如果不能匹配,则终止. 结果,这样超时了...估计是调用函数上面花费了些时间. 后来直接在函数中记录出现的个数,这样就不超时了. #include <iostream> #include <stdio.h> #include <st…
Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23667   Accepted: 9492 Description The 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…
Description The 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,…
题意:给你两个字符串p和s,求出p在s中出现的次数. 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 我先想直接把p接到s前面,之后求Next数组对strlen(p)取余==0的就可以,之后WA.最后发现A AASSAAS的时候有bug,只有又想到在p和s中间加个不可能出现的字符'$'就可以了,接着就A了. #include <bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f…
本题就是给出非常多对字符串,然后问一个字符串在另外一个字符串出现的次数. 就是所谓的Strstr函数啦. Leetcode有这道差点儿一模一样的题目. 使用KMP算法加速.算法高手必会的算法了. 另外看见讨论说什么使用KMP还超时,最大可能是没有真正理解next table的含义,写了错误的代码,故此尽管自己执行结果正确,可是却没有真正发挥next table的作用.使得算法退化为暴力法了,所以执行正确,但超时. KMP參考: http://blog.csdn.net/kenden23/arti…
Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49378   Accepted: 19617 Description The 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 quot…
题意: 给两组字符串a和b,求a在b中出现的次数 关于KMP: 马拉车算法是处理回文串,而KMP是处理前后缀的相同字符串的最长长度. a | a | b | a | a | f | a | a 数组 p [ ] 下标为 i a | a | b | a | a | c 数组 t [ ]下标为 j -1| 0 | 1 | 0 | 1 | 2 next [ ] shu数组的值 比较这两组字符串,当p[5]!=t[5]时,如果暴力,那么 i 回溯到1,j 回溯到0,重新比较,可是在之前比较过的0~4下标…
题意:统计其中一个子串的出现次数 题解:即KMP算法中j==m的次数 //作者:1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include &l…
2017-08-13 19:31:47 writer:pprp 对kmp算法有了大概的了解以后,虽然还不够深入,但是已经可以写出来代码,(可以说是背会了) 所以这道题就作为一个模板,为大家使用吧. 题目大意:给你一个子串P和一个主串S,求在主串中有多少个子串? 代码如下:(需要注意的点我都标记好了,两个函数可以直接用) #include <iostream> #include <cstdio> #include <cstdlib> #include <cstrin…
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> using namespace std; ]; void GetNext(char t[]){//求next数组 int j,k,len; j=; k=-; next[]=-; len=strlen(t); while(j<len){ ||t[j]==t[k]){ ++j; ++k; next[j]=k…
http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <cmath> #include <map> #include <queue> using namespace std;…
题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有NC个不同的字符,所以我们可以把字符串看成是一个NC进制的串,然后计算出字符串的前缀HASH.然后枚举起点判断子串的HASH值是否已经存在.因为有了前缀HASH值,所以转移是O(1)的. #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #in…
Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在学习后缀数组的时候已经做过一遍了,但是现在主攻字符串hash,再用字符串hash写一遍. 这题的思路是这样的: 1)取较短的串的长度作为high,然后二分答案(每次判断长度为mid=(low+high)>>1是否存在,如果存在就增加下界:不存在就缩小上界): 2)主要是对答案的判断(judge函数…
[题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每一行枚举其中两个字符串,检查之前行中对应的两列里是否重复即可.但是如何判重. 一开始想的把字符串做成pair然后用map映射为行号,但是TLE. 后来想到用hash判重,可能是因为哈希函数不够好,还是TLE... 总之这道题卡了三个小时,一直TLE. 枚举每一列,对枚举到的那一列从小到大排序,然后找到相邻两个…
Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15900   Accepted: 5494 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 Oulipo Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description The French author Georges Perec (1936�1…