HDU1890

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define Keytree (ch[ ch[root][1] ][0])
const int maxn = 100010;
struct node {
    int num,id;
}in[maxn];
int id[maxn];
int cmp(node a,node b){
    if(a.num!=b.num) return a.num<b.num;
    return a.id<b.id;
}
struct SplayTree{
    int tot,root;
    int pre[maxn];
    int size[maxn];
    int ch[maxn][2];
    inline void Rotate(int x, int c) {    // 旋转, c=0 左旋, c=1 右旋
        int y = pre[x];
        pushdown(y);
        pushdown(x);
        ch[y][!c] = ch[x][c];
        if ( ch[x][c] )    pre[ ch[x][c] ] = y;
        pre[x] = pre[y];
        if ( pre[y] )    ch[ pre[y] ][ ch[pre[y]][1] == y ] = x;
        ch[x][c] = y;
        pre[y] = x;
        pushup(y);
    }
    inline void Splay(int x, int f) {    // 把结点x转到结点f的下面
        pushdown(x);
        while ( pre[x] != f ) {
            int y = pre[x], z = pre[y];
            pushdown(z);    pushdown(y);    pushdown(x);    // 旋转前必须先去除反转标记
            if ( pre[ pre[x] ] == f ) {
                Rotate(x, ch[pre[x]][0] == x);
            }
            else {
                if ( ch[z][0] == y ) {
                    if ( ch[y][0] == x ) 
                        Rotate(y, 1), Rotate(x, 1);
                    else 
                        Rotate(x, 0), Rotate(x, 1);
                }
                else {
                    if ( ch[y][0] == x ) 
                        Rotate(x, 1), Rotate(x, 0);
                    else 
                        Rotate(y, 0), Rotate(x, 0);
                }
            }
        }
        pushup(x);
        if ( f == 0 )    root = x;
    }
    inline void Select(int k, int f) {    // 把第k个点旋转到f的下面
        int x = root;
        while ( 1 ) {
            pushdown(x);
            if ( k == size[ ch[x][0] ] + 1 ) 
                break;
            if ( k <= size[ ch[x][0] ] )
                x = ch[x][0];
            else {
                k -= (size[ ch[x][0] ] + 1);
                x = ch[x][1];
            }
        } 
        Splay(x, f);
    }
    inline void del_root(){//删除根节点
        int t=root;
        if(ch[root][1]) {
            root=ch[root][1];
            Select(1,0);//把右子树中序遍历的第一个点旋转到根(因为这个点的左儿子肯定为空)
            ch[root][0]=ch[t][0];//将原先根节点的左子树接到当前根节点的左子树上
            if(ch[t][0]) pre[ch[t][0]]=root;
        }
        else 
            root=ch[root][0];

        pre[root]=0;
        pushup(root);
    }
    inline void pushup(int x){
        size[x]=size[ ch[x][0] ] + size[ ch[x][1] ] +1;
    }
    inline void pushdown(int x){
        if(flip[x]){
            flip[x]=0;
            flip[ch[x][0]]^=1;
            flip[ch[x][1]]^=1;
            swap(ch[x][0],ch[x][1]);
        }
    }
    void Newnode(int &x,int f){
        x=++tot;
        pre[x]=f;
        ch[x][0]=ch[x][1]=0;
        flip[x]=0;
        size[x]=1;
    }
    void build(int &x,int l,int r,int f){
        if(l>r) return ;
        int mid=(l+r)>>1;
        Newnode(x,f);
        map[id[mid]]=x;
        build(ch[x][0],l,mid-1,x);
        build(ch[x][1],mid+1,r,x);
        pushup(x);
    }
    void init(int n){
        int i;
        pre[0]=ch[0][0]=ch[0][1]=0;
        size[0]=flip[0]=tot=0;
        for(i=1;i<=n;i++) {
            scanf("%d",&in[i].num);
            in[i].id=i;
        }
        sort(in+1,in+n+1,cmp);
        for(i=1;i<=n;i++) id[in[i].id]=i;
        map[id[1]] = 1;
        map[id[n]] = 2;
        Newnode(root,0);
        Newnode(ch[root][1],root);
        build(Keytree,2,n-1,ch[root][1]);
        pushup(ch[root][1]);
        pushup(root);
    }
    void solve(int n){
        for(int i=1;i<=n;i++){
            Splay(map[i],0);
            printf("%d",i+size[ch[root][0]]);
            if(i<n) printf(" ");
            flip[ch[root][0]]^=1;
            del_root();
        }
        puts("");
    }
    int map[maxn];
    int flip[maxn];
}spt;
int main(){
    int n;
    while(scanf("%d",&n),n)    {
        if(n==1) {scanf("%*d");printf("1\n");continue;}
        spt.init(n);
        spt.solve(n);
    }
    return 0;
}


风格更新后:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define maxn 100010
#define LL long long int
#define Key_value ch[ch[root][1]][0]

struct node
{
	int num,id;
}in[maxn];

int id[maxn];
bool cmp(node a,node b)
{
	if(a.num != b.num)	return a.num < b.num;
	return a.id < b.id;
}

struct SplayTree
{
	int pre[maxn],ch[maxn][2],size[maxn],flip[maxn],map[maxn],root,cnt;
	
	void init(int n)
	{
		root = cnt = 0;
		pre[0] = ch[0][0] = ch[0][1] = 0;
		size[0] = flip[0] = 0;
		for(int i = 1;i <= n;i++)
		{
			scanf("%d",&in[i].num);
			in[i].id = i;
		}
		sort(in+1,in+n+1,cmp);
		for(int i = 1;i <= n;i++)	id[in[i].id] = i;
		map[id[1]] = 1;
		map[id[n]] = 2;
		NewNode(root,0);
		NewNode(ch[root][1],root);
		BuildTree(Key_value,2,n-1,ch[root][1]);
		PushUp(ch[root][1]);
		PushUp(root);
	}

	void BuildTree(int & x,int l,int r,int father)
	{
		if(l > r)	return;
		int mid = (l+r) >> 1;
		NewNode(x,father);
		map[id[mid]] = x;
		if(l < mid)
			BuildTree(ch[x][0],l,mid-1,x);
		if(r > mid)
			BuildTree(ch[x][1],mid+1,r,x);
		PushUp(x);
	}

	void NewNode(int & r,int father)
	{
		r = ++cnt;
		pre[r] = father;
		ch[r][0] = ch[r][1] = 0;
		size[r] = 1;
		flip[r] = 0;
	}

	void PushDown(int r)
	{
		if(flip[r])
		{
			flip[r] = 0;
			flip[ch[r][0]] ^= 1;
			flip[ch[r][1]] ^= 1;
			swap(ch[r][0],ch[r][1]);
		}
	}
	
	void PushUp(int r)
	{
		size[r] = size[ch[r][0]] + size[ch[r][1]] + 1;
	}

	void Rotate(int x,int kind)
	{
		int y = pre[x];
		PushDown(y);
		PushDown(x);
		ch[y][!kind] = ch[x][kind];
		pre[ch[x][kind]] = y;
		if(pre[y])
			ch[pre[y]][ch[pre[y]][1]==y] = x;
		pre[x] = pre[y];
		ch[x][kind] = y;
		pre[y] = x;
		PushUp(y);
	}

	void Splay(int r,int goal)
	{
		PushDown(r);
		while(pre[r] != goal)
		{
			int y = pre[r],z = pre[y];
			PushDown(z);	PushDown(y);	PushDown(r);
			if(pre[pre[r]] == goal)
			{
				Rotate(r,ch[pre[r]][0] == r);
			}
			else
			{
				int kind = ch[pre[y]][0] == y;
				if(ch[y][kind] == r)
				{
					Rotate(r,!kind);
					Rotate(r,kind);
				}
				else
				{
					Rotate(y,kind);
					Rotate(r,kind);
				}
			}
		}
		PushUp(r);
		if(goal == 0)	root = r;
	}

	void RotateTo(int k,int goal)
	{
		int r = root;
		while(1)
		{
			PushDown(r);
			if(k == size[ch[r][0]] + 1)
				break;
			if(k <= size[ch[r][0]])
				r = ch[r][0];
			else
			{
				k -= size[ch[r][0]] + 1;
				r = ch[r][1];
			}
		}
		Splay(r,goal);
	}

	void del_root()
	{
		int t = root;
		if(ch[root][1])
		{
			root =  ch[root][1];
			RotateTo(1,0);
			ch[root][0] = ch[t][0];
			if(ch[t][0])	pre[ch[t][0]] = root;
		}
		else root = ch[root][0];
		pre[root] = 0;
		PushUp(root);
	}

	void solve(int n)
	{
		init(n);
		for(int i = 1;i <= n;i++)
		{
			Splay(map[i],0);
			printf("%d",i+size[ch[root][0]]);
			if(i < n)	printf(" ");
			flip[ch[root][0]] ^= 1;
			del_root();
		}
		puts("");
	}
}spt;

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF && n)
	{
		if(n == 1)
		{
			scanf("%*d");
			printf("1\n");
			continue;
		}
		spt.solve(n);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 100080
#define Key_value ch[ch[root][1]][0]
int Rank[maxn],Map[maxn];

struct Item
{
	int key,id;
	bool operator < (const Item & a) const
	{
		if(key != a.key)return key < a.key;
		return id < a.id;
	}
}item[maxn];

struct SpalyTree
{
	int pre[maxn],ch[maxn][2],size[maxn],flip[maxn];
	int root,cnt;

	void init(int n)
	{
		cnt = root = 0;
		ch[0][0] = ch[0][1] = size[0] = pre[0] = flip[0] = 0;
		NewNode(root,1,0);
		NewNode(ch[root][1],n,root);
		Buildtree(Key_value,2,n-1,ch[root][1]);
		PushUp(ch[root][1]);
		PushUp(root);
	}

	void NewNode(int & r,int k,int father)
	{
		r = ++cnt;
		ch[r][0] = ch[r][1] = flip[r] = 0;
		pre[r] = father;
		size[r] = 1;
		Map[Rank[k]] = r;
	}

	void PushDown(int x)
	{
		if(flip[x])
		{
			flip[x] = 0;
			flip[ch[x][0]] ^= 1;
			flip[ch[x][1]] ^= 1;
			swap(ch[x][0],ch[x][1]);
		}
	}

	void PushUp(int x)
	{
		int l = ch[x][0],r = ch[x][1];
		size[x] = size[l] + size[r] + 1;
	}

	void Buildtree(int & r,int L,int R,int father)
	{
		if(L > R)return;
		int mid = (L+R)>>1;
		NewNode(r,mid,father);
		Buildtree(ch[r][0],L,mid-1,r);
		Buildtree(ch[r][1],mid+1,R,r);
		PushUp(r);
	}

	void Rotate(int x,int kind)
	{
		int y = pre[x];
		PushDown(y);
		PushDown(x);
		ch[y][!kind] = ch[x][kind];
		pre[ch[x][kind]] = y;
		if(pre[y])
			ch[pre[y]][ch[pre[y]][1]==y] = x;
		pre[x] = pre[y];
		ch[x][kind] = y;
		pre[y] = x;
		PushUp(y);
	}

	void Splay(int r,int goal)
	{
		PushDown(r);//为什么去了这个会超时.假设pre[r] == goal。而且r有懒惰标记
		//如果这里没有PushDown。这里懒惰标记就直接给del_root函数搞没了。。
		while(pre[r] != goal)
		{
			int y = pre[r],z = pre[y];
			PushDown(z);	PushDown(y);	PushDown(r);//这里不加会超时,想想
			if(pre[pre[r]] == goal)
				Rotate(r,ch[pre[r]][0] == r);
			else 
			{
				int kind = (ch[pre[y]][0] == y);
				if(ch[y][kind] == r)
				{
					Rotate(r,!kind);
					Rotate(r,kind);
				}
				else 
				{
					Rotate(y,kind);
					Rotate(r,kind);
				}
			}
		}
		PushUp(r);
		if(goal == 0)	root = r;
	}
	
	int Get_Kth(int r,int k)
	{
		PushDown(r);
		int t = size[ch[r][0]] + 1;
		if(t == k)
			return r;
		if(t > k)
			return Get_Kth(ch[r][0],k);
		else return Get_Kth(ch[r][1],k-t);
	}

	void del_root()
	{
		int t = root;
		if(ch[root][1])
		{
			root = ch[root][1];
			int x = Get_Kth(root,1);
			Splay(x,0);
			ch[root][0] = ch[t][0];
			if(ch[t][0])	pre[ch[t][0]] = root;
		}
		else root = ch[root][0];
		pre[root] = 0;
		PushUp(root);
	}

	void solve(int n)
	{
		init(n);
		for(int i = 1;i <= n;i++)
		{
			Splay(Map[i],0);
			printf("%d",i+size[ch[root][0]]);
			flip[ch[root][0]] ^= 1;
			del_root();
			if(i == n)	printf("\n");
			else printf(" ");
		}
	}
}spt;

int main()
{
	//freopen("in.txt","r",stdin);
	int n;
	while(scanf("%d",&n)!=EOF && n)
	{
		if(n == 1)
		{
			scanf("%*d");
			printf("1\n");
			continue;
		}
		for(int i = 1;i <= n;i++)
		{
			scanf("%d",&item[i].key);
			item[i].id = i;
		}
		sort(item+1,item+1+n);
		for(int i = 1;i <= n;i++)
		{
			Rank[item[i].id] = i;
		}//Rank数组表示第几个进来的排第几。
		spt.solve(n);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1 字符串处理 5 1.1 KMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 e-KMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3 Manacher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4 AC 自动机 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5 后缀数组 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.5.1 DA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.5.2 DC3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.6 后缀自动机 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.6.1 基本函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.6.2 例题 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.7 字符串 hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2 数学 25 2.1 素数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.1.1 素数筛选(判断 <MAXN 的数是否素数) . . . . . . . . . . . . . . . . 25 2.1.2 素数筛选(筛选出小于等于 MAXN 的素数) . . . . . . . . . . . . . . . 25 2.1.3 大区间素数筛选(POJ 2689) . . . . . . . . . . . . . . . . . . . . . . . 25 2.2 素数筛选和合数分解 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.3 扩展欧几里得算法(求 ax+by=gcd 的解以及逆元) . . . . . . . . . . . . . . . 27 2.4 求逆元 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.4.1 扩展欧几里德法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.4.2 简洁写法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.4.3 利用欧拉函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.5 模线性方程组 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.6 随机素数测试和大数分解 (POJ 1811) . . . . . . . . . . . . . . . . . . . . . . . 29 2.7 欧拉函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.7.1 分解质因素求欧拉函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.7.2 筛法欧拉函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.7.3 求单个数的欧拉函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.7.4 线性筛(同时得到欧拉函数和素数表) . . . . . . . . . . . . . . . . . . 32 2.8 高斯消元(浮点数) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.9 FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.10 高斯消元法求方程组的解 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.10.1 一类开关问题,对 2 取模的 01 方程组 . . . . . . . . . . . . . . . . . . . 37 2.10.2 解同余方程组 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.11 整数拆分 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.12 求 A B 的约数之和对 MOD 取模 . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.13 莫比乌斯反演 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.13.1 莫比乌斯函数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.13.2 例题:BZOJ2301 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.14 Baby-Step Giant-Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.15 自适应 simpson 积分 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.16 斐波那契数列取模循环节 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.17 原根 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.18 快速数论变换 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.18.1 HDU4656 卷积取模 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.19 其它公式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.19.1 Polya . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 kuangbin 1 ACM Template of kuangbin 3 数据结构 56 3.1 划分树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.2 RMQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 3.2.1 一维 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 3.2.2 二维 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 3.3 树链剖分 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.3.1 点权 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.3.2 边权 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3.4 伸展树(splay tree) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.4.1 例题:HDU1890 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.4.2 例题:HDU3726 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 3.5 动态树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.5.1 SPOJQTREE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.5.2 SPOJQTREE2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 3.5.3 SPOJQTREE4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.5.4 SPOJQTREE5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3.5.5 SPOJQTREE6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.5.6 SPOJQTREE7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 3.5.7 HDU4010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 3.6 主席树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 3.6.1 查询区间多少个不同的数 . . . . . . . . . . . . . . . . . . . . . . . . . . 95 3.6.2 静态区间第 k 大 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 3.6.3 树上路径点权第 k 大 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.6.4 动态第 k 大 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 3.7 Treap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 3.8 KD 树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 3.8.1 HDU4347 K 近邻 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 3.8.2 CF44G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 3.8.3 HDU4742 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 3.9 替罪羊树 (ScapeGoat Tree) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 3.9.1 CF455D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 3.10 动态 KD 树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 3.11 树套树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 3.11.1 替罪羊树套 splay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 4 图论 130 4.1 最短路 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 4.1.1 Dijkstra 单源最短路 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 4.1.2 Dijkstra 算法 + 堆优化 . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 4.1.3 单源最短路 bellman_ford 算法 . . . . . . . . . . . . . . . . . . . . . . . 131 4.1.4 单源最短路 SPFA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.2 最小生成树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 4.2.1 Prim 算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 4.2.2 Kruskal 算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 4.3 次小生成树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 4.4 有向图的强连通分量 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 4.4.1 Tarjan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 4.4.2 Kosaraju . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 4.5 图的割点、桥和双连通分支的基本概念 . . . . . . . . . . . . . . . . . . . . . . . 138 4.6 割点与桥 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 4.6.1 模板 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 kuangbin 2 ACM Template of kuangbin 4.6.2 调用 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 4.7 边双连通分支 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 4.8 点双连通分支 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 4.9 最小树形图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 4.10 二分图匹配 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 4.10.1 邻接矩阵(匈牙利算法) . . . . . . . . . . . . . . . . . . . . . . . . . . 149 4.10.2 邻接表(匈牙利算法) . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 4.10.3 Hopcroft-Karp 算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 4.11 二分图多重匹配 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 4.12 二分图最大权匹配(KM 算法) . . . . . . . . . . . . . . . . . . . . . . . . . . 153 4.13 一般图匹配带花树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 4.14 一般图最大加权匹配 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 4.15 生成树计数 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 4.16 最大流 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 4.16.1 SAP 邻接矩阵形式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 4.16.2 SAP 邻接矩阵形式 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 4.16.3 ISAP 邻接表形式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 4.16.4 ISAP+bfs 初始化 + 栈优化 . . . . . . . . . . . . . . . . . . . . . . . . . 165 4.16.5 dinic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 4.16.6 最大流判断多解 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 4.17 最小费用最大流 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 4.17.1 SPFA 版费用流 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 4.17.2 zkw 费用流 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4.18 2-SAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 4.18.1 染色法(可以得到字典序最小的解) . . . . . . . . . . . . . . . . . . . . 172 4.18.2 强连通缩点法(拓扑排序只能得到任意解) . . . . . . . . . . . . . . . . 173 4.19 曼哈顿最小生成树 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 4.20 LCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 4.20.1 dfs+ST 在线算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 4.20.2 离线 Tarjan 算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 4.20.3 LCA 倍增法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 4.21 欧拉路 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 4.21.1 有向图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 4.21.2 无向图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 4.21.3 混合图 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 4.22 树分治 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 4.22.1 点分治 -HDU5016 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 4.22.2 * 点分治 -HDU4918 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 4.22.3 链分治 -HDU5039 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 5 搜索 205 5.1 Dancing Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 5.1.1 精确覆盖 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 5.1.2 可重复覆盖 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 5.2 八数码 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 5.2.1 HDU1043 反向搜索 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 6 动态规划 212 6.1 最长上升子序列 O(nlogn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 6.2 背包 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 6.3 插头 DP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 kuangbin 3 ACM Template of kuangbin 6.3.1 HDU 4285 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 7 计算几何 218 7.1 二维几何 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 7.2 三维几何 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 7.3 平面最近点对 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 7.4 三维凸包 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 7.4.1 HDU4273 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 8 其他 249 8.1 高精度 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 8.2 完全高精度 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 8.3 strtok 和 sscanf 结合输入 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 8.4 解决爆栈,手动加栈 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 8.5 STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 8.5.1 优先队列 priority_queue . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 8.5.2 set 和 multiset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 8.6 输入输出外挂 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 8.7 莫队算法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 8.7.1 分块 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 8.7.2 Manhattan MST 的 dfs 顺序求解 . . . . . . . . . . . . . . . . . . . . . . 260 8.8 VIM 配置 .

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值