哈希表字符串匹配
来源:互联网 发布:淘宝网智能手机 编辑:程序博客网 时间:2024/06/15 22:39
//冲突概率为sqrt(n)#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>#define ull unsigned long longusing namespace std;const ull B=1e8+7;const int dmax=101000;char s[dmax],s1[dmax];int hash(char *a,char *b){ull x=strlen(a),y=strlen(b),al=0,bl=0,t=1;if (x>y)return -1;for (int i=0;i<x;i++){t*=B;al=al*B+a[i];bl=bl*B+b[i];}for (int i=0;i<=y-x;i++){if (al==bl)return i;if (i<y-x)bl=bl*B-s[i]*t+s[i+x];}return -1;}int main(){gets(s1);gets(s);printf("%d\n",hash(s1,s));return 0;}
0 1
- 哈希表字符串匹配
- ACE_Hash_Map_Manager_Ex ACE哈希表字符串处理
- 注解匹配表字段与实体字段
- 两个表字段匹配优化对比
- 【邻接表字符串Hash】【HDU1800】Flying to the Mars
- 数据库表字段 实体类字段 命名不匹配
- mysql 建表字符集
- mysql 建表字符集
- mysql 建表字符集
- mysql表字符编码问题
- mysql建表字符集
- 编程从广义表字符串表示中直接获取广义表有关信息
- mysql 表字符集和校对规则
- 建表字符集导致乱码问题
- PowerDesigner设置表字符编码 utf-8
- DataBase: oracle表字符数过长
- PowerDesigner设置表字符编码 utf-8
- 使用PreparedStatementSetter 设置参数跟 表字段类型不匹配出现的错误
- 自定义View笔记一
- [android]_[Async异步任务使用]
- 重建二叉树
- iOS UIProgressView控件用法
- iOS开发篇——UITextField
- 哈希表字符串匹配
- UISlider用法总结
- Codeforces 621A Wet Shark and Odd and Even
- 刚试了一下,浏览器里可以玩 Windows 95
- 重设(Resize)Bitmap大小以及获取到圆形头像(Rounded Avatar)的方法
- A*启发式搜索算法详解 人工智能
- 补充:函数间只能用this
- [android]_[ImageView点击变暗]
- Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers