哈希表
哈希表,期望复杂度
支持插入,判断是否存在两种操作
作为一个玄学算法,当然是无法避免冲突的啦
不过可以使用链表接在后面,问题不大
void hashin(int x)//插入元素x
{
int t=x%mod+1;//mod自定(其实192560817比较合适)
for(int i=fst[t];i;i=nxt[i])
if(hash[i]==x)
return;//已经存在了
hash[++last]=x,nxt[last]=fst[t],fst[t]=last;
//这下把存图的数组用上了
}
bool check(int x)//判断x是否存在
{
int t=x%mod+1;
for(int i=fst[x];i;i=nxt[i])
if(hash[i]==x)
return 1;
return 0;
}