我好鱼啊QAQ没有发现这个坑点

P3370 【模板】字符串哈希

%%%dalao
by 九牧啊 @ 2017-11-09 16:26:53


这题我不用map过不了……
by vani_prcups @ 2017-11-09 16:46:12


用双哈希比较稳
by 日月影 @ 2017-11-09 16:51:03


这题不是set吗qwq
by Lolierl @ 2017-11-09 16:52:04


用双哈希比较稳
by λᴉʍ @ 2017-11-09 16:57:05


然而单hash可过啊 (/////w/////)
by fy0123 @ 2017-11-09 17:07:19


单蛤快,双蛤稳
by iotang @ 2017-11-09 17:24:09


单哈希,24ms...
by bzy369258147 @ 2017-12-10 19:07:22


```cpp #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> using namespace std; const int MAXN = 10000; int ans = 0; struct hashmap { string str; hashmap *next = NULL;//指针记得指向空... }a[MAXN*10]; bool myfind(hashmap &x, string &in) { if(x.str == in) return false; if(x.next == NULL) { x.str = in; x.next = new hashmap;//不是很懂的可以百度一下,new+类型名返回一个指向该类型的指针 return true; //每次存入为后面可能出现的碰撞做准备,不过貌似会浪费空间...不过题水是吧QWQ } return myfind(*x.next, in);//递归搜索链表 } void myhash(string &in)//散列过程,不解释 { long long hashnum = in.length(); for(int i = 0; i < in.length(); i++) hashnum += in[i]; hashnum *= hashnum; hashnum = hashnum >> 4;//位运算,向右移4位,也可以看做hashnum /= 10000;不过位运算逼格高,速度快QWQ hashnum %= (MAXN*10); if(myfind(a[hashnum], in)) ans++; } int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) { string putin; cin >> putin; myhash(putin); } printf("%d\n", ans); return 0; } ```
by Explorer_CYC @ 2018-04-01 15:37:52


|