hash處理字串問題

2021-10-23 18:07:22 字數 947 閱讀 3446

#include#include#include#includeusing namespace std;

const int mod=1000000007; //mod為計算hash值時的模數

const int p=10000019; //p為計算hash值時的進製數

vectorans;

//字串hash

long long hashfunc(string str),h2[maxn]=;

//pr1存放str1的所有《子串hash值,子串長度》,pr2同理

vector>pr1,pr2;

//init函式初始化powp函式

void init(int len)

}//calh函式計算字串str的hash值

void calh(ll h,string &str)

//calh函式計算字串str的hash值

void calh(ll h,string &str)

} //calsinglesubh計算h[i...j]

int calsinglesubh(ll h,int i,int j)

//對稱點為i,字串長len,在[l,r]裡二分回文半徑

//尋找最後乙個滿足條件「hashl==hashr」的回文半徑

//等價於尋找第乙個滿足條件"hashl!=hashr"的回文半徑,然後減1即可

//iseven當求奇回文時為0,當求偶回文時為1

int binarysearch(int l,int r,int len,int i,int iseven)

return l-1; //返回最大回文半徑

} int main()

//偶回文

for(int i=0;iprintf("%d\n",ans);

return 0;

}

字串hash問題

一些介紹字串hash的文章 字串雜湊函式 題目傳送 hdu 4821 string 13年長春現場賽的字串水題。不過沒有接觸過這類題,所以不會做。所謂字串hash,通常是把乙個字串對映為乙個整數。我這裡採用的是bkdrhash函式。穩定性最好的乙個字串hash函式。ac include includ...

Hash 字串 字串雜湊

luo gu luogu luogup 3370 p3370 p337 0如題,給定n個字串 第i個字串長度為mi,字串內包含數字 大小寫字母 請求出n個字串中共有多少個不同的字串。第一行包含乙個整數n,為字串的個數。接下來n行每行包含乙個字串,為所提供的字串。輸出包含一行,包含乙個整數,為不同的字...

白兔的字串 字串hash

原題 一道典型的字串hash,至於hash,這裡講的非常好。一開始用map函式一直超時,後來改用unordered map就過了,至於這2個map的區別,這裡講的挺清楚的。之後去查了一下其它方法,發現還有一種方法是手寫map函式 強 指明 大佬 unordered map是跑了600ms,重寫跑了1...