线段树+字典树+树状数组+树链剖分+树的分治
文章平均质量分 77
秋天的风--
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
展开
-
hdu 4325
#include//数据弱线段树延迟更新水过 #define N 100100 struct node { int x,y,yanchi,num; }a[N*4]; void build(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].yanchi=0; a[t].num=0; if(x==y) return ; int temp原创 2013-11-13 19:55:30 · 642 阅读 · 0 评论 -
树的直径,树的重心,树的分冶
要是利用了反证法: 假设 s-t这条路径为树的直径,或者称为树上的最长路 现有结论,从任意一点u出发搜到的最远的点一定是s、t中的一点,然后在从这个最远点开始搜,就可以搜到另一个最长路的端点,即用两遍广搜就可以找出树的最长路 证明: 1 设u为s-t路径上的一点,结论显然成立,否则设搜到的最远点为T则 dis(u,T) >dis(u,s) 且 dis(u,T)>dis(u转载 2014-09-30 16:56:41 · 464 阅读 · 0 评论 -
poj 3237 树链剖分模板(用到线段树lazy操作)
/* 本体在spoj375的基础上加了一些操作,用到线段树的lazy操作模板类型 */ #include #include #include #include #include #include #include using namespace std; #define N 11000 #define inf 0x3fffffff int head[N]; int son[N];//记录与当前点原创 2014-09-29 16:25:05 · 511 阅读 · 0 评论 -
hdu 5044 树链剖分
转载:http://blog.csdn.net/qinzhenhua100/article/details/39716851转载 2014-10-10 16:30:35 · 324 阅读 · 0 评论 -
hdu 3804树链剖分+离线操作
/* 树链刨分+离线操作 题意:给你一棵树,和询问x,y 从节点x--节点1的小于等于y的最大值. 解:先建一个空树,将树的边权值从小到大排序,将询问y按从小到大排序 对于每次询问y将小于等于y的边权值的边加入,在进行询问将结果储存最后输出即可 易错点:要考虑到节点1到节点1的情况需特判。 */ #pragma comment(linker, "/STACK:102400000,1原创 2014-09-30 15:49:48 · 991 阅读 · 0 评论 -
hdu 5029树链剖分
/* 解:标记区间端点,按深度标记上+下-。 然后用线段树维护求出最小的,再将它映射回来 */ #pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include using namespace std; #define N 100500 struct node {原创 2014-10-10 10:44:51 · 515 阅读 · 0 评论 -
poj 1741 树的分治
/* 树的分治 题意:求树上两点间的距离<=k的点对数目; 因为n<=10000,暴搜一定会超时,所以很明显用的是树的点分治进行处理:点分治即为把树进行递归,分别对每个子树进行操作, 然后把每个子树的情况综合起来,对于这道题目,首先找到树根(即树的重心),对于该树,统计dis[i]+dis[j]<=k的数量, 将无根树转化成有根树进行观察。满足条件的点对有两种情况:两个点的路径横跨树根,两个点位于原创 2014-10-01 16:39:57 · 524 阅读 · 0 评论 -
hdu 4670 树的分治-求点对的个数
/* 树的分治 因为树的点权值可达到10^15,注意手动扩栈,还有int64 题意:给你一棵树,给你一些素数,给你每个点一个权值且每个权值均可由这些素数组成。现在定义任意任意两点的价值为他们路径上的权值相乘。求这样的点对的权值为立方数的个数 解: 如果直接求得话会超int64,不可行 由立方数的性质可得,一个数可有素数组成,对于这些素数可以分解为这些素数相乘的形式如,24=(2^3)*(3^1);原创 2014-10-02 20:03:54 · 925 阅读 · 0 评论 -
poj 2114 树的分治 可作模板
/* 啊啊啊啊啊啊啊本题证明一个问题,在实际应用中sort比qsort块 还有memset这类初始化能不加尽量别加,很浪费时间 原来的程序把qsort该成sort,去掉一个无用memset就a了时间不到一半 题意:和poj1741差不多,不过本题求的是dis[i]+dis[j]==dis[k]; */ #include #include #include #include using namesp原创 2014-10-01 20:00:22 · 561 阅读 · 0 评论 -
poj 1655 求树的重心
/* 求树的重心,一个dfs即可 重心的意义,在对树进行分治的时候可以避免N^2的极端复杂度(从退化链的一端出发),保证NlogN的复杂度 tit=Max(tit,num[v]); tit=Max(tit,n-1-num[u]);其中num[u]代表u的子树的节点数(包括u) */ #include #include #include #define N 21000 #define inf原创 2014-10-01 14:36:23 · 492 阅读 · 0 评论 -
hdu 4871 树的分治+最短路记录路径
/* 题意:给你一些节点和一些边,求最短路径树上是k个节点的最长的路径数。 解:1、求出最短路径树--spfa加记录 2、树上进行操作--树的分治,分别处理子树进行补集等运算 */ #include #include #include #include #include #include #define ll __int64 using namespace std; #define N原创 2014-10-04 17:14:40 · 1106 阅读 · 0 评论 -
spoj 375 树链剖分模板
/* 只是一道树链刨分的入门题,作为模板用。 */ #include #include #include #include #include #include #include using namespace std; #define N 11000 #define inf 0x3fffffff int head[N]; int son[N];//记录与当前点相连的数目最多的子节点的下标 int原创 2014-09-29 15:52:14 · 521 阅读 · 0 评论 -
hdu 5023 线段树延迟更新+状态压缩
/* 线段树延迟更新+状态压缩 */ #include #define N 1100000 struct node { int x,y,yanchi,sum; }a[N*4]; int lower[31]; void build(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].yanchi=0; if(x==y){ a[t].sum=low原创 2014-09-22 15:27:02 · 677 阅读 · 0 评论 -
hdu 1698区间延迟更新
#include #define N 100100 struct node { int x,y,yanchi; }a[N*4];//注意数组范围 void build(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].yanchi=1; if(x==y) return ; int temp=t int mid=(x+y)/2; b原创 2013-11-13 20:22:38 · 670 阅读 · 0 评论 -
poj3468区间延迟更新模板题
#include #include #define N 100000 struct st{ int x,y; __int64 yanchi,sum; }a[N*4]; __int64 b[N]; void build(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].yanchi=0; if(x==y) { a[t原创 2013-09-03 18:49:41 · 789 阅读 · 0 评论 -
hdu 1556 线段树区间延迟更新好题
656mS#include #include #define N 110000 struct node { int x,y,yanchi,sum; }a[N*10]; void build(int t,int x,int y) { a[t].x=x; a[t].y=y; a[t].sum=0; a[t].yanchi=0; if(x==y)return ; int temp=t*2; int mi原创 2014-05-21 21:25:26 · 509 阅读 · 0 评论 -
hdu 1075 字典树
#include #include struct node { int num,i; node *a[27]; char s[20];//定义局部不是空的 node() { num=0; for(i=0;i a[i]=NULL; } }*root; char s2[20],str[20],str1[3100],s1[20],h[20]; void insert(int l原创 2013-11-18 17:07:35 · 710 阅读 · 0 评论 -
hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html原创 2013-11-19 21:00:56 · 806 阅读 · 0 评论 -
hdu 1251简单字典树
#include #include #include using namespace std; struct node { int num,i; node *a[27]; node (){ num=0; for(i=0;i a[i]=NULL; } }*root; char str[20]; void insert(int len,node *root) { int原创 2013-11-17 16:41:04 · 687 阅读 · 0 评论 -
poj 2001
#include #include #include using namespace std; struct trie { trie *a[27]; int v; }*h,*t; int len,k; char str[1100][30]; void build(int count,trie *h) { int i,j; h->v++; if(count>len)retu原创 2013-11-17 15:37:28 · 703 阅读 · 0 评论 -
hdu 1166 树状数组模板题
#include #include #define N 51000 int c[N],n; int number(int x) { return x&-x; } void creat(int a,int x) { int i; for(i=a;i c[i]+=x; } int sum(int x) { int h=0,i; for(i=x;i>0;i-=number原创 2013-11-19 20:42:10 · 748 阅读 · 0 评论 -
字典树
个人觉得这个模板比较好 http://www.tuicool.com/articles/6Fv2Ej 模仿这个模板我写的poj上的2001 #include #include #include using namespace std; struct node { int num; node *a[27]; node () { int i; num=0; for原创 2013-11-17 16:18:00 · 689 阅读 · 0 评论 -
hdu 4046 树状数组
#include #include #define N 51000 char s[N]; int a[N],n; int number(int x) { return x&-x; } void creat(int x,int k) { int i; for(i=x;i a[i]+=k; } int sum(int x) { int su=0,i; for(i=原创 2014-03-25 14:45:29 · 499 阅读 · 0 评论