08 2013 档案
bzoj 2653 middle(陈立杰) 二分枚举 + 可持久化线段树
摘要:http://www.lydsy.com/JudgeOnline/problem.php?id=2653题目描述: 给长度为20000的序列。求左端点在[a,b]和右端点在[c,d]中所有的子序列,最大的中位数。#include #include #include #include using namespace std;const int N = 20005;struct info{ int sum, mxl, mxr; info(){} info(int val){ sum = mxl = mxr = val; }};info operator + (... 阅读全文
posted @ 2013-08-18 20:48 tobec 阅读(599) 评论(0) 推荐(0) 编辑
在线lca
摘要:#include #include #include #include #include using namespace std;const int maxm = 16;const int maxn = 1 e[maxn]; int d[maxn],p[maxn][maxm]; void dfs_(int v,int f) { p[v][0] = f; for(int i=1;i d[b]) { swap(a , b); } b = up_(b , d[b]-d[a]); if(a == ... 阅读全文
posted @ 2013-08-18 12:33 tobec 阅读(367) 评论(0) 推荐(0) 编辑
hdu 4679 Terrorist’s destroy 树形DP
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4679f[u],g[u],k[u]:分别代表u延伸出去的最长边长,第二长边长,第三长边长;ff[u]:f[u]对应的子节点gg[u]:g[u]对应的子节点h[u]:沿着u的父节点方向的最长边dp[u][0]:以u的所有子节点为根的子树中的子树的直径最大值dp[u][1]:以u的所有子节点为根的子树中的子树的直径次大值flag[u]:dp[u][0]对应的u的子节点ddp[u]:除以u为根的子树外的子树的直径#include #include #include #include #include using n 阅读全文
posted @ 2013-08-15 20:51 tobec 阅读(210) 评论(0) 推荐(0) 编辑
poj 3580 SuperMemo splay tree(重口味)
摘要:http://poj.org/problem?id=3580给一个长度为N(N 2 #include 3 #include 4 #include 5 using namespace std; 6 #define inf (1= nowsz) return 0; 63 int x = tree[0].chd[1]; 64 while(1) { 65 pushdown(x); 66 int u = tree[x].chd[0]; 67 int v = tree[x].chd[1]; 68 if(tree... 阅读全文
posted @ 2013-08-12 13:37 tobec 阅读(347) 评论(0) 推荐(0) 编辑
hdu 1890 Robotic Sort splaytree+懒惰标记
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1890给一个长度为N(N 2 #include 3 #include 4 #include 5 using namespace std; 6 #define inf (1<<29) 7 const int maxn = 100010; 8 int n , splaysz; 9 struct node {10 int p,chd[2],sz,flag;11 node (int P=0) {12 chd[0]=chd[1]=0;sz=0;13 p = P; f... 阅读全文
posted @ 2013-08-12 13:35 tobec 阅读(232) 评论(0) 推荐(0) 编辑
bzoj 1588 [HNOI2002]营业额统计 splay tree
摘要:http://www.lydsy.com/JudgeOnline/problem.php?id=1588splay tree 中的一些操作的说明:sc函数: inline void sc(int y,int x,int p) { 如果p==0,则y是x的父亲,x是y的左儿子; 如果p==1,则y是x的父亲,x是y的右儿子; }rot函数: inline void rot(int x) { y是x的父亲节点; 如果x是y的左儿子,则w=0;如果x是y的右儿子,则w=1; 设p是y的父亲; 对x,y,p进行zig或zag操作; } 效果:每次rot(x),x向根靠近一单位深度splay函数: vo 阅读全文
posted @ 2013-08-10 15:04 tobec 阅读(198) 评论(0) 推荐(0) 编辑
bzoj 1503 [NOI2004]郁闷的出纳员 splay tree
摘要:http://www.lydsy.com/JudgeOnline/problem.php?id=1503#include #include #include #include using namespace std;#define inf (1 tree[now].v; if(tree[now].chd[w]) now = tree[now].chd[w]; else { tree[++splaysz] = node(now,val); tree[now].chd[w]= splaysz; updat... 阅读全文
posted @ 2013-08-10 15:02 tobec 阅读(236) 评论(0) 推荐(0) 编辑
《ACM国际大学生程序设计竞赛--题目与解读》训练笔记
摘要:ACM国际大学生程序设计竞赛(ACM-ICPC)是国际上公认的水平最高、规模最大、影响最深的计算机专业竞赛,目前全球参与人数达20多万。《ACM国际大学生程序设计竞赛(ACM-ICPC)系列丛书:题目与解读》作者将16年的教练经验与积累撰写成本系列丛书,全面、深入而系统地将ACM-ICPC展现给读者、本系列丛书包括《ACM国际大学生程序设计竞赛:知识与入门》、《ACM国际大学生程序设计竞赛:算法与实现》、《ACM国际大学生程序设计竞赛:题目与解读》、《ACM国际大学生程序设计竞赛:比赛与思考》等4册,其中《ACM国际大学生程序设计竞赛:知识与入门》介绍了ACM-ICPC的知识及其分类、进阶.. 阅读全文
posted @ 2013-08-10 12:13 tobec 阅读(1815) 评论(0) 推荐(0) 编辑
Live Archive 3490 - Generator 概率
摘要:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=214&page=show_problem&problem=1491We can generate a random string by generating a sequence of random characters and concatenating them together. Each character is chosen independently from the first 阅读全文
posted @ 2013-08-10 11:28 tobec 阅读(281) 评论(0) 推荐(0) 编辑
uva 10288 Coupons 概率
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1229Problem FCouponsInput:standard inputOutput:standard outputTime Limit:2secondsMemory Limit:32 MBCoupons in cereal boxes are numbered1ton, and a set of one of each is required 阅读全文
posted @ 2013-08-10 11:16 tobec 阅读(764) 评论(0) 推荐(0) 编辑
hdu 4654 k-edge connected components
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4654stoer-wagner算法 + dfs#include #include #include #include #include using namespace std;#define inf (1 vst[maxn];vector pa , pb;int prim(int n) { memset(vis,0,sizeof(vis)); memset(d,0,sizeof(d)); int mincut = 0 , tmp = -1; s = t = -1; int to... 阅读全文
posted @ 2013-08-09 15:55 tobec 阅读(335) 评论(0) 推荐(0) 编辑
hdu 4647 Another Graph Game 博弈
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4647树上的博弈,直接把边权平分到两边的节点上,然后排个序,从大往小取#include #include #include #include using namespace std;const int maxn = 100100;int n , m;double a[maxn];int main() { while(~scanf("%d%d",&n,&m)) { for(int i=1;i=1;i-=2) { ans += a[i] - a[i-1]; ... 阅读全文
posted @ 2013-08-08 19:34 tobec 阅读(164) 评论(0) 推荐(0) 编辑
hdu 4655 Unshuffle 搜索
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4665搜索;搜索前的剪枝:对于某个数num,第一次出现的num标记为0,最后一个出现的num标记为1;搜索中的剪枝:如果不能匹配,一定是错的#include #include #include #include using namespace std;const int maxn = 2002;int a[maxn] , t[maxn] , id[maxn] , n , T , pos[maxn][5];int idd[maxn];int f[maxn] , g[maxn] , cf , cg;void in 阅读全文
posted @ 2013-08-08 19:24 tobec 阅读(589) 评论(0) 推荐(0) 编辑
hdu 4006 The kth great number SBT
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4006直接用SBT中的get_max_Kth函数#include #include #include #include using namespace std;#define LL long longconst int maxn = 100010;#define ls T[x].l#define rs T[x].r#define lls T[ls].l#define lrs T[ls].r#define rls T[rs].l#define rrs T[rs].rstruct SBT{ //左子树指针,右子树 阅读全文
posted @ 2013-08-05 22:27 tobec 阅读(197) 评论(0) 推荐(0) 编辑
zoj 3612 Median SBT
摘要:维护一个集合,插入与删除操作,每一步结束之后,输出中位数#include #include #include #include using namespace std;#define LL long longconst int maxn = 100010;#define ls T[x].l#define rs T[x].r#define lls T[ls].l#define lrs T[ls].r#define rls T[rs].l#define rrs T[rs].rstruct SBT{ //左子树指针,右子树指针,大小,键值 int l,r,sz,key; void init(){ . 阅读全文
posted @ 2013-08-05 18:27 tobec 阅读(171) 评论(0) 推荐(0) 编辑
hdu 3473 Minimum Sum 划分树
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3473对于xl,xl+1……xr,使得[xi-x]和最小,显然x应当为其中的中位数。中位数可以通过求K大数解决,划分树可搞。对于求和,分为两部分,小于x的部分,大于y的部分,在建树的时候也保存下来分到左子树中的数的和。最终的和为ave*(lnum-rnum)+rsum-lsumave为中位数,lnum为左子数的数量,也就是小于中位数的数量,rnum为右子数,lsum表示小于中位数部分的和#include #include #include #include using namespace std;#defin 阅读全文
posted @ 2013-08-05 10:54 tobec 阅读(252) 评论(0) 推荐(0) 编辑
poj 2104 K-th Number 划分树
摘要:划分树是在建树的过程中保存快速排序。划分树同样以1 5 2 6 3 7为例:根据中位数mid,将区间划分成左子树中的数小于等于mid,右子树中的数大于等于mid,得到这样一棵划分树: [1 5 2 6 3 7] [1 2 3] [5 6 7] [1 2] [3] [5 6] [7] [1] [2] [5] [6]注意要保持下标的先后顺序不变对每一个区间,用sum[i]记录区间的左端点left到i有几个进入了左子树,即有几个数小于等于mid用对应的下标区间建线段树:(这里下标区间对应的是排序后的数列) [1 6] [1 3] [4 6] [1 2] [3] [4 5][6] [1][2... 阅读全文
posted @ 2013-08-04 00:41 tobec 阅读(225) 评论(0) 推荐(0) 编辑
poj 2104 K-th Number 归并树
摘要:归并树是在建树的过程中保存归并排序。归并树以1 5 2 6 3 7为例:把归并排序递归过程记录下来即是一棵归并树: [1 2 3 5 6 7] [1 2 5] [3 6 7] [1 5] [2] [6 3] [7] [1][5] [6][3]用对应的下标区间建线段树:(这里下标区间对应的是原数列) [1 6] [1 3] [4 6] [1 2] [3] [4 5][6] [1][2] [4][5]每次查找[l r]区间的第k大数时,在[1 2 3 4 5 6 7]这个有序的序列中二分所要找的数x,然后对应到线段树中去找[l r]中比x小的数有几个,即x的rank。由于线段树中任意... 阅读全文
posted @ 2013-08-03 22:13 tobec 阅读(206) 评论(0) 推荐(0) 编辑
hdu 4616 树形DP
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4616转载自http://blog.csdn.net/tri_integral/article/details/9499037题意:给出一棵树,树上每个节点都有权值,某些点有陷阱。可以任选起点,每个点只能走过一次,如果走到某点不能再走或者走到某个点恰好走了C个陷阱就停在该点,问最后路径上点权之和能得到的最大值。题解:树形DP。用dp[u][j]表示以u为根的子树上,从某点走到u且走过j个陷阱能得到的最大值;考虑如果最优解走过了k个陷阱,如果k!=C,那么其起点和终点都可以为没有陷阱的点,如果k=C,那么起点或 阅读全文
posted @ 2013-08-03 00:17 tobec 阅读(243) 评论(0) 推荐(0) 编辑
hdu 4612 Warm up 双连通分量
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4612双连通分量 + 树的直径一样的代码 C++ 交了两遍过的 , 看了网上的第一行 , 手动 设定 栈空间#pragma comment(linker,"/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;#define inf (1 g[maxn];void solve() { idx = cnt = top = 0; memset(d 阅读全文
posted @ 2013-08-03 00:11 tobec 阅读(205) 评论(0) 推荐(0) 编辑
Project Euler 5 Smallest multiple
摘要:http://projecteuler.net/problem=5Answer:232792560 阅读全文
posted @ 2013-08-02 23:18 tobec 阅读(89) 评论(0) 推荐(0) 编辑
Project Euler 4 Largest palindrome product
摘要:http://projecteuler.net/problem=4答案:906609 阅读全文
posted @ 2013-08-02 23:01 tobec 阅读(99) 评论(0) 推荐(0) 编辑
hdu 4614 Vases and Flowers 线段树
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4614线段树 , 中间有二分操作#include #include #include #include using namespace std;#define ls (rt>1)const int maxn = 50050;struct node { int l , r; int sum; int lazy;}t[maxn mid) return query(rs,l,r); else if(r mid) change(rs , l , r , val); else if(r ... 阅读全文
posted @ 2013-08-02 17:16 tobec 阅读(186) 评论(0) 推荐(0) 编辑
hdu 4628 Pieces 状态压缩DP
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4628#include #include #include #include using namespace std;bool is[1=0;i--) { f[i] = (1<<29); for(int j=i+1;j<=n;j = (j+1)|i) { if(is[j-i]) { f[i] = min(f[i] , f[j] + 1); } } } printf("%d\n" , ... 阅读全文
posted @ 2013-08-02 17:13 tobec 阅读(179) 评论(0) 推荐(0) 编辑
hdu 4638 Group 线段树
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4638线段树 离线处理题意为询问一段区间里的数能组成多少段连续的数。先考虑从左往右一个数一个数添加,考虑当前添加了i-1个数的答案是x,那么添加完i个数后的答案是多少?可以看出,是根据a[i]-1和a[i]+1是否已经添加而定的,如果a[i]-1或者a[i]+1已经添加一个,则段数不变,如果都没添加则段数加1,如果都添加了则段数减1。设v[i]为加入第i个数后的改变量,那么加到第x数时的段数就是sum{v[i]}(1#include #include #include using namespace std; 阅读全文
posted @ 2013-08-02 13:58 tobec 阅读(229) 评论(0) 推荐(0) 编辑
hdu 4635 Strongly connected 强连通分量
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4635强连通分量缩点之后+简单计算,具体见代码#include #include #include #include using namespace std;const int maxn = 100100;struct Edge { int v , next; Edge () {} Edge (int v , int next) : v(v) , next(next) {};}edge[maxn ans) ans = tt; } ans -= mm; ... 阅读全文
posted @ 2013-08-01 22:44 tobec 阅读(165) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示