人生第一次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
pla文件怎么看,pla文件用什么打开?
pl1文件怎么看,pl1文件用什么打开?
pl文件怎么看,pl文件用什么打开?
pl0文件怎么看,pl0文件用什么打开?
pkt文件怎么看,pkt文件用什么打开?
pkm文件怎么看,pkm文件用什么打开?
pks文件怎么看,pks文件用什么打开?
pka文件怎么看,pka文件用什么打开?
pkh文件怎么看,pkh文件用什么打开?
pkg文件怎么看,pkg文件用什么打开?