字符串哈希 哈希表
1.字符串哈希 方法概述: 选取两个合适的互质常数b,h(b<h),把字符串看成b进制数,算出这个数模h 设H(C,k)为前k个字符构成的字符串的哈希值,则:H(C',k)=H(C,k+n)-H(C,k)*b n --------具体见《信息学奥赛一本通提高篇》 关于正确性:可以用双哈希降低出现相同哈希值的概率 取10 9 +7和10 9 +9,就几乎不可能发生冲突,因为它们是孪生质数 板子题: poj3461 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define R register 5 #define go(i,a,b) for(R int i=a;i<=b;i++) 6 #define il inline 7 #define ll unsigned long long // 记得是unsigned long long 8 #define M 1000001 9 using namespace std; 10 il int rd() 11 { 12 int x= 0 ,y= 1 ; char c= getchar(); 13 while (c< ' 0 ' ||c> ' 9 ' ){ if (c== ' - ' )y=- 1 ;c= getchar();} 14 while (c>= ' 0