散列技术处理字符串
散列技术处理字符串
Dream-chasing ant
鄙人水平不高,建立博客初心只是想留一份回忆给自己。
展开
-
Power Strings POJ - 2406
传送门 hash的模板题,但要用scanf否则超时。也可以用KMP算法来做 #include<cstdio> #include<cstring> #include<iostream> using namespace std; const int maxn=1e6+10; const int seed=131; typedef long long ll; ll _base[maxn],_hash[maxn]; int len; char s[maxn]; ll str_原创 2020-07-27 22:42:42 · 74 阅读 · 0 评论 -
String HDU - 4821
传送门 文章目录前言思路代码 前言 终于解决了这道题,之前看了一下午题解,都没看明白,现在终于清楚一点了。不管目前有什么样的困难,只要坚持不放弃,就可能出现转机。 思路 hash+map去重,思路非常的巧妙。我现在感觉跟KMP思想有点像。如果我们简单的暴力枚举,那么它会出现回退,这浪费了很多时间。我们不让他回退,直接一点一点后移。还有就是循环边界要想的特别清楚,可以举几个例子 代码 #include<cstdio> #include<map> #include<cstr原创 2020-07-27 10:57:13 · 82 阅读 · 0 评论 -
Stammering Aliens
Stammering Aliens hash+二分 #include<cstdio> #include<map> #include<cstring> #include<iostream> using namespace std; const int maxn=4e4+5; const int seed=31; typedef long long ll; ll _base[maxn],_hash[maxn]; int len; map<ll,ll>原创 2020-07-24 16:57:25 · 71 阅读 · 0 评论 -
散列技术处理字符串
文章目录前言常用的字符串hash函数 前言 字符串的hash是通过某种字符串hash函数将不同的字符串映射到不同的数字,配合其他数据结构或者STL,进行判重,统计,查询等操作 常用的字符串hash函数 hash[i]=(hash[i-1]*p+id(s[i]))%mod,即hash[i]是字符串的前i个字符串组成的前缀的hash值,而idx(s)为字符s的一个自定义索引 基于字符串hash函数,可以求字符串的任何一个子串的hash值:hash[l…r]=(hash[r]-hash[l-1]*p^(r-原创 2020-07-24 11:02:04 · 321 阅读 · 0 评论