随笔分类 - 算法。。
摘要:一般写的字典树都是双数组的形式,但是当字符的数量很多时,就会占用大量的内存,初始化操作也会变慢。这时,就可以用左孩子右兄弟的写法,来以时间换空间。下面是自己写的一个: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 const int maxnode=100000; 8 9 struct Trie10 {11 char ch[maxnode];12 int left[maxnode],right[maxnode],cnt;13 bool flag[maxnode];14 15 ...
阅读全文
摘要:左偏树是一种不平衡的二叉树,特点是:堆+快速的合并 每个结点包含4个元素v,d,r,l。。。。右边的D总是比左边的D小。。。向左偏。。。。合并操作都是向右边的子树递归的,时间复杂度低O(log(n1)+log(n2))。因为合并比较快。。。所以。。基本操作大都是用合并完成的。。。。。写起来非常简单。。。。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 const int maxn=100010; 8 int tot=0; 9 10 struct leftistheapnode11 {12 int v...
阅读全文
摘要:一些关于GCD的代码。。。。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 typedef long long int LL; 8 9 LL EX_GCD(LL a,LL b,LL& x,LL& y)10 {11 if(b==0)12 {13 x=1;y=0;14 return a;15 }16 else17 {18 LL ret=EX_GCD(b,a%b,x,y);19 int t=x;20 ...
阅读全文

浙公网安备 33010602011771号