哈希表
简单来说$hash$表就是依据原信息建立虚点
通过临接表相连,同时记录正确信息
事实上这是一种比较随机的映射,我们通过映射的元素查询原信息
同时因为$\%mod$的原因我们的复杂度趋近$O(1)$.
(csp-s模拟测试53 v)
struct map_hash{ struct node{int to,n;double val;int len;}e[31000001]; int tot=0; int head[MAXN];int len=0; double &operator[](int state){ int st=state*len%mod+1; for(int i=head[st];i;i=e[i].n){ if(e[i].to==state&&e[i].len==len) return e[i].val; } e[++tot].to=state; e[tot].val=-1.0; e[tot].len=len; e[tot].n=head[st]; head[st]=tot; return e[tot].val; } }f;
二元组加和和比较大小
struct node{ int fir;int sec; friend node operator +(node a,node b){ return (node){a.fir+b.fir,a.sec+b.sec}; } }; inline node minn(node a,node b){ if(a.fir==b.fir)return a.sec<b.sec?a:b; return a.fir<b.fir?a:b; }