人生的第一次hash交给了模板题。
讲道理,还没有别人快排要快,就比暴力快那么一点。。。
难道我写的hash就那么菜么?
我想了想,光是处理字符串就O(n*len)。。
这是hash的正确写法吗?我都开始怀疑自己了。
不管怎样,把代码附上,以后可能会用。
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> using namespace std; int n; string h[1000007], s; const int mod = 1000007; long long hash() bool insert() int main() printf("%d", ans); return 0; }View Code
学习了别人的写法,200ms,感觉这才是正确姿势。
原来的我还是太naive了。
1 #include <cstdio> 2 #include <cstring> 3 #define ULL unsigned long long 4 5 const int MAXN = 1000008, p = 1000007; 6 int n, ans, cnt; 7 int head[MAXN], next[MAXN]; 8 ULL val[MAXN]; 9 char s[MAXN]; 10 11 inline bool insert(ULL x) 12 22 23 inline void ha() 24 30 31 int main() 32 41 printf("%d", ans); 42 return 0; 43 }View Code
上一篇:如何退出scla命令行界面和scala常用命令
下一篇: 遇到的Docker常用命令
模板 hash









