人生第一次hash


人生的第一次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



上一篇:【模板】二分图匹配

下一篇:docker sh build.sh运行过程中卡着不动


模板 hash
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图