2018.6.10数据结构串讲_HugeGun

 链接: https://pan.baidu.com/s/1uQwLZAT8gjENDWLDm7-Oig 密码: mk8p

 

@echo off
: )
shuju
test
test_
fc test.out test.ans
if errorlevel == 1 pause
goto )
对拍
#include<stdio.h>
int a[100010],Next[100010],pre[100010],head,last;
void add(int x,int y)//在标号为x的数后面插入标号为y的数 
{
    int nex=Next[x];
    Next[x]=y,pre[y]=x;
    pre[nex]=y,Next[y]=nex;
    if(x==last)last=y;
}
void del(int x)//在链表中删掉标号为x的数
{
    int prex=pre[x],nex=Next[x];
    Next[prex]=nex,pre[nex]=prex;
    pre[x]=Next[x]=0;
} 
int main()
{
    return 0;
}
链表
#include<stdio.h>
int head[100010],Next[200020],poi[200020],w[200020],ed;
void add(int a,int b,int c,int d)//在a,b之间加一条权值为c的边,d==1是为无向边,d==0是为有向边 
{
         Next[++ed]=head[a],head[a]=ed,poi[ed]=b,w[ed]=c;
    if(d)Next[++ed]=head[b],head[b]=ed,poi[ed]=a,w[ed]=c;
}
void dfs(int x,int f)//遍历一棵树,f是x的父亲 
{
    int i;
    for(i=head[x];i;i=Next[i])if(poi[i]!=f)
        dfs(poi[i],x);
}
int main()
{
    return 0;
}
邻接表
 1 #include<stdio.h>
 2 int ch[100010][2],w[100010],ed,root;
 3 void add(int *k,int x)
 4 {
 5     if(!*k)
 6     {
 7         *k=++ed,w[*k]=x;
 8         return ;
 9     }
10     int d=x>w[*k];
11     add(&ch[*k][d],x);
12 }
13 int main()
14 {
15     return 0;
16 }
BST
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 int ch[100010][2],w[100010],c[100010],s[100010],r[100010],ed,root;
 4 void maintain(int x){if(x)s[x]=c[x]+s[ch[x][0]]+s[ch[x][1]];}
 5 void rotate(int *k,int d)
 6 {
 7     int p=ch[*k][d^1];
 8     ch[*k][d^1]=ch[p][d];
 9     ch[p][d]=*k;
10     maintain(*k);
11     maintain(p);*k=p;
12 }
13 void add(int *k,int x)
14 {
15     if(!*k)
16     {
17         *k=++ed;w[*k]=x,s[*k]=c[*k]=1,ch[*k][0]=ch[*k][1]=0,r[*k]=rand();
18         return ;
19     }
20     s[*k]++;
21     if(w[*k]==x){c[*k]++;return ;}
22     int d=x>w[*k];
23     add(&ch[*k][d],x);
24     if(r[ch[*k][d]]<r[*k])rotate(k,d^1);
25 }
26 int del(int *k,int x)
27 {
28     if(!*k)return 0;
29     if(w[*k]==x)
30     {
31         if(c[*k]>1){s[*k]--;c[*k]--;return 1;}
32         if(!ch[*k][0]){*k=ch[*k][1];return 1;}
33         if(!ch[*k][1]){*k=ch[*k][0];return 1;}
34         if(r[ch[*k][0]]<r[ch[*k][1]])rotate(k,1);
35         else rotate(k,0);
36         return del(k,x);
37     }
38     int d=x>w[*k];
39     if(del(&ch[*k][d],x)){s[*k]--;return 1;}
40     return 0;
41 }
42 int findrank(int x)
43 {
44     int k=root,ret=0;
45     while(k)
46     {
47         int pp=s[ch[k][0]];
48         if(x==w[k])return ret+pp;
49         else if(x<w[k])k=ch[k][0];
50         else ret+=(pp+c[k]),k=ch[k][1];
51     }
52     return ret;
53 }
54 int findwei(int x)
55 {
56     int k=root;
57     while(k)
58     {
59         int pp=s[ch[k][0]];
60         if(x<=pp)k=ch[k][0];
61         else if(x>pp+c[k])x-=pp+c[k],k=ch[k][1];
62         else return w[k];
63     }
64     return 0;
65 }
66 int findqian(int x)
67 {
68     int k=root,ret=0;
69     while(k)
70     {
71         if(w[k]<x)ret=w[k],k=ch[k][1];
72         else k=ch[k][0];
73     }
74     return ret;
75 }
76 int findhou(int x)
77 {
78     int k=root,ret=0;
79     while(k)
80     {
81         if(w[k]>x)ret=w[k],k=ch[k][0];
82         else k=ch[k][1];
83     }
84     return ret;
85 }
86 int main()
87 {
88     return 0;
89 }
treap

 

posted @ 2018-06-07 18:43  HugeGun  阅读(489)  评论(0编辑  收藏  举报