【字符串RK匹配】POJ 1200
来源:互联网 发布:淘宝网禁止出售滥用 编辑:程序博客网 时间:2024/04/29 12:34
转换为nc进制!
复杂度O(len)。
#include <stack>#include <map>#include <string>#include <cstdio>#include <cstdlib>#include <string.h>#include <iostream>using namespace std;#define N 16000005#define FRE freopen("a.txt","r",stdin)char str[20000000];int hash[N];int cc[200];int main(){ int n,nc; while(scanf("%d%d",&n,&nc)!=EOF){ int i,j; scanf("%s",str); int len = strlen(str); int cnt = 0; memset(cc,0,sizeof(cc)); memset(hash,0,sizeof(hash)); int tmp = 1; for(j=1;j<n;j++)tmp*=nc; i=0; while(str[i]){ if(!cc[str[i]]){ cc[str[i]] = ++cnt; } i++; if(cnt==nc)break; } int d = 0; for(i=0;i<n;i++){ d = d*nc + cc[str[i]]; } hash[d] = 1; int ans = 1; for(i=0;i+n<len;i++){ d = nc*(d-tmp*cc[str[i]])+ cc[str[i+n]]; if(!hash[d]){ hash[d] = 1; ans++; } } printf("%d\n",ans); } return 0;}
- 【字符串RK匹配】POJ 1200
- 字符串匹配之RK算法
- 字符串匹配的RK算法+随机
- 字符串匹配 之 RK(Rabin-Karp)
- 字符串的模式匹配:RK算法
- RK字符串匹配随机算法(C语言)
- 字符串匹配算法综述:BF、RK、KMP、BM、Sunday
- 字符串匹配算法 -- 暴力破解法(朴素法),RK算法,KMP算法
- LeetCode Implement strStr()(朴素的字符串匹配,RK算法,KMP算法)
- poj 2192 字符串匹配
- POJ 3080 (字符串匹配)
- RK(字符串哈希)
- poj 1226 暴力字符串匹配
- POJ 1936(字符串匹配)
- RK
- *RK
- 串的模式匹配算法---RK
- 串的模式匹配算法---RK
- 解决VS2005 新建项目模版消失的问题【亲身验证】
- Data partitioning
- VARIANT
- 用vc开发office自动化入门文档(转载msdn)
- JS 操作XML
- 【字符串RK匹配】POJ 1200
- 使用Editplus编辑运行Java程序
- 182页习题16
- dos 命令提取文件名
- Socket通信基本流程
- C#计算一段程序运行时间的三种方法
- 被忽视的控件UIPageControl
- 图像识别与图论
- 献给初学者——IT还是“挨踢”? 一个过来人的浅显心得