人生第一次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
spc文件怎么看,spc文件用什么打开?
0文件怎么看,0文件用什么打开?
sparseimage文件怎么看,sparseimage文件用什么打开?
sp文件怎么看,sp文件用什么打开?
dv文件怎么看,dv文件用什么打开?
soundpack文件怎么看,soundpack文件用什么打开?
dus文件怎么看,dus文件用什么打开?
dtw文件怎么看,dtw文件用什么打开?
spdf文件怎么看,spdf文件用什么打开?
0文件怎么看,0文件用什么打开?