
数据结构
文章平均质量分 81
u010660276
这个作者很懒,什么都没留下…
展开
-
二叉树后继
二叉树后继如果有指向父亲的结点,则:1.如果当前结点有右儿子,或者当前结点是根结点,则后继结点为右子树的最左叶节点;2.否则,如果当前结点是父结点的左儿子,则后继结点就是父结点;(其实是第三种情况的一个特例,即自己是第0代祖先,返回第一代祖先)3.否则,向上遍历,直到n-1代祖先是n代祖先的左儿子,则后继结点为n代祖先;或者遍历到根节点后未找到符合的n代结点,则该结点为中序遍历的最后结点,没有后原创 2017-07-21 21:48:13 · 1142 阅读 · 1 评论 -
2015 Multi-University Training Contest 6 (hdu 5357 - Easy Sequence)栈的应用
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 643 Accepted Submission(s): 185Problem Description soda has a string conta原创 2015-08-11 20:19:18 · 494 阅读 · 0 评论 -
2015 Multi-University Training Contest 5(hdu5343 - 5352)网络流+yy+(哈夫曼树+dp)
MZL’s xorProblem DescriptionMZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n)(A_i+A_j)(1\leq i,j\leq n) The xor of an array B is defi原创 2015-08-06 12:00:59 · 889 阅读 · 0 评论 -
最近点对
#include #include #include #include #include #include #include #include #include #include #include using namespace std; const in原创 2015-07-20 10:39:38 · 412 阅读 · 0 评论 -
快速排序
#include<bits/stdc++.h>using namespace std;int a[100];int N;void QuickSort(int l,int r){ if(l<r) { int s=a[l]; int i=l,j=r+1; while(true) { whil原创 2015-07-12 14:41:33 · 380 阅读 · 0 评论 -
2013 ACM-ICPC吉林通化全国邀请赛(hdu 4493 - 4599)(并查集+dp+数学+判奇环+差分约束)
D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2437 Accepted Submission(s): 859Problem Description Luxer is a really bad guy. He d原创 2015-07-11 16:49:22 · 1166 阅读 · 0 评论 -
带权并查集(hdu2818)
Building BlockTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3552 Accepted Submission(s): 1067Problem DescriptionJohn are playin原创 2015-03-22 21:23:48 · 387 阅读 · 0 评论 -
并查集+treap实现名次数(BZOJ2733)
2733: [HNOI2012]永无乡Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1351 Solved: 710[Submit][Status]Description永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示。某些岛之间原创 2015-03-03 20:44:27 · 487 阅读 · 0 评论 -
BestCoder17(B,C)good
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-11-09 19:42:27 · 461 阅读 · 0 评论 -
最小生成树(kruskal)Codeforces 472D
D. Design Tutorial: Inverse the ProblemThere is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an in原创 2014-10-08 22:14:43 · 1064 阅读 · 0 评论 -
2014上海网络赛(DLX,树链剖分,java)
kuangbin大神的题解原创 2014-09-28 11:28:45 · 727 阅读 · 0 评论 -
伸展树splay+uva11922
#include#include#includeusing namespace std;struct Node{ Node *ch[2]; int s; int flip; int v; int cmp(int k) const { int d = k - ch[0]->s; if(d == 1) retu原创 2014-09-11 21:53:03 · 606 阅读 · 0 评论 -
Treap实现名次树
// LA5031 Graph and Queries// Rujia Liu#includestruct Node { Node *ch[2]; // 左右子树 int r; // 随机优先级 int v; // 值 int s; // 结点总数 Node(int v):v(v) { ch[0] = ch[1] = NULL; r = rand(); s = 1; }原创 2014-09-10 20:39:17 · 692 阅读 · 0 评论 -
线段树+并查集uva1455Kingdom
There were n cities in an ancient kingdom. In the beginning of the kingdom, all cities were isolated. Kings ordered their subjects to construct roads connecting cities. A lot of roads were built with原创 2014-08-20 14:36:02 · 500 阅读 · 0 评论 -
字典树+map+hdu1800
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-08-17 21:47:38 · 471 阅读 · 0 评论 -
Trie树+并查集+欧拉回路poj2513
Language:DefaultColored SticksTime Limit: 5000MS Memory Limit: 128000KTotal Submissions: 30307 Accepted: 8007DescriptionYou are given a bunch of wooden st原创 2014-08-15 21:37:59 · 453 阅读 · 0 评论 -
树的直径hdu3721
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-08-13 20:20:03 · 1106 阅读 · 0 评论 -
LCA+并查集应用(好题)poj3728
Language:DefaultThe merchantTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 3143 Accepted: 1047DescriptionThere are N cities in a country, and原创 2014-08-13 15:07:21 · 1183 阅读 · 0 评论 -
划分树(2010天津现场赛)hdu3727
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-08-08 20:14:01 · 540 阅读 · 0 评论 -
hdu3724+Trie树
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-08-08 17:55:48 · 537 阅读 · 0 评论 -
划分树(模板)poj2104
Language:DefaultK-th NumberTime Limit: 20000MS Memory Limit: 65536KTotal Submissions: 37013 Accepted: 11911Case Time Limit: 2000MSDescriptionYou are原创 2014-08-07 21:45:13 · 502 阅读 · 0 评论 -
划分树
划分树的定义 划分树定义为,它的每一个节点保存区间[lft,rht]所有元素,元素顺序与原数组(输入)相同,但是,两个子树的元素为该节点所有元素排序后(rht-lft+1)/2个进入左子树,其余的到右子树,同时维护一个num域,num[i]表示lft->i这个点有多少个进入了左子树。 划分树的Sample 如果由下而上看这个图,我们就会发现它和归并排序的(转载 2014-08-07 20:55:25 · 462 阅读 · 0 评论 -
线段树+树状数组+二分+划分树+主席树+hdu4417
Online JudgeOnline ExerciseOnline TeachingOnline ContestsExercise AuthorF.A.QHand In HandOnline AcmersForum | DiscussStatistical ChartsProblem ArchiveRealtime Judge Statu原创 2014-08-07 11:19:56 · 866 阅读 · 0 评论 -
Codeforces Round #FF (Div.2 )(C,D)
C. DZY Loves SequencesDZY has a sequence a, consisting of n integers.We'll call a sequence ai, ai + 1, ..., aj(1 ≤ i ≤ j ≤ n) a subsegment of the sequencea. The value (j - i + 1) denot原创 2014-07-14 11:13:09 · 576 阅读 · 0 评论 -
Codeforces Round #254 (Div. 2)(并查集,线段树)
B. DZY Loves Chemistrytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDZY loves chemistry, and he enjoys mixing chemi原创 2014-07-07 15:01:23 · 493 阅读 · 0 评论 -
Codeforces Round #250 (Div. 2)(B,C,D并查集)
比赛的时候没想明白。。。原创 2014-06-03 22:48:39 · 632 阅读 · 0 评论 -
并查集向量偏移
http://poj.org/problem?id=1182这道食物链题目是并查集的变型,很久以前做的一次是水过的,这次仔细地研究了这“食物链”,无非就是运用向量偏移,从以前节点与节点转化成向量与向量的关系。我们可以把矛盾的产生得益于向量偏移时的结果。直接引出向量偏移的运用。 下面是POJ一位大牛这样理解的,本人稍有修改。对于集合里的任意两个元素a,b而言,它们之间转载 2014-05-01 22:42:50 · 1385 阅读 · 0 评论 -
SD五一联赛(加权并查集)
ArnyTime Limit: 3000MS Memory limit: 65536K题目描述Bad working coordinator was the everlasting trouble of their spaceship. Arny already had been working under this trouble while his not ve原创 2014-05-01 15:50:32 · 828 阅读 · 0 评论 -
stl应用+uva11020
#include#include#include#includeusing namespace std;struct node{ int a,b; bool operator <(const node &r)const { return a<r.a||(a==r.a&&b<r.b); }};multiset s;multiset::原创 2014-04-22 21:09:06 · 496 阅读 · 0 评论 -
并查集+poj食物链
方法一:#include#include#include#includeusing namespace std;const int maxn=50010;int pra[maxn],rank[maxn];int n,k;void init(){ for(int i=0;i<=n;i++) { pra[i]=i; rank[i]=原创 2014-04-16 21:38:38 · 483 阅读 · 0 评论 -
树uva699
问处于同一列的节点的和。输出形式略坑#include#include#include#includeusing namespace std;const int maxn=10000;const int INF=100000000;struct node{ int data; node *left,*right; node(int num):data(原创 2014-03-10 11:11:21 · 539 阅读 · 0 评论 -
树uva112
这题的输入有些麻烦,参考了人家的代码,很简洁,很厉害#include #include #include #include #include #include using namespace std; int flag; int t_sum(int n,int sum) { int data; char c; cin>>c原创 2014-03-04 22:30:28 · 846 阅读 · 1 评论 -
指针建树uva548
题意:给出中序遍历和后序遍历,找出最短路径上的叶结点的值思路:先建树然后dfs找#include#include#include#include#include#includeusing namespace std;struct node{ int data; node *left,*right; node() { data=原创 2014-03-01 20:21:16 · 763 阅读 · 0 评论 -
矩阵转置uva10895
用一个vector存储转置后的矩阵。#include#include#include#includeusing namespace std;const int maxn=10010;struct node{ int col,data; node(int c,int d):col(c),data(d){}};vector matrix[maxn];int n,原创 2014-03-01 18:13:07 · 640 阅读 · 0 评论 -
uva10410(dbl)
给出BFS和DFS求树#include#include#include#includeusing namespace std;const int maxn=1010;int n;vector ans[maxn],sub[maxn],pos[maxn];int bfs[maxn],dfs[maxn];void init(){ for(int i=0;i<=n;i++)原创 2014-02-28 23:10:09 · 1086 阅读 · 0 评论 -
树的重建uva536
给出先序遍历和中序遍历求后续遍历 #include #include void build(int n, char *s1, char *s2, char *s) { if(n <= 0) return; int p = strchr(s2, s1[0]) - s2;原创 2014-02-28 22:12:38 · 609 阅读 · 0 评论 -
树+栈+队列(表达式树)uva11234
题目的最关键部分是进行二叉树建树, 以及层次遍历逆序输出,还有利用栈的“括号匹配”思想。 二叉树的基本结构是,父结点都是操作符,子节点都是数字。 对于给出的序列, 从左到右遍历,遇到代表数字的小写则建立一个无儿子的树,然后把根结点指针入栈, 遇到代表操作符的大写字母,则从栈中弹出两个根结点,然后建立一个以大写字母为根,弹出的两个操作数为左右儿子的树,再把这个新树的根结点指针压入栈。如此循环下去。原创 2014-02-28 15:15:01 · 735 阅读 · 0 评论 -
栈uva11111
跟括号匹配相似#include#include#include#include#include#includeusing namespace std;struct node{ int sz,cap; node(int s,int c):sz(s),cap(c){}};int Abs(int x){ return x>=0?x:-x;}int m原创 2014-02-27 23:22:13 · 587 阅读 · 0 评论 -
并查集带删除操作uva11987(好)
题意:初始有N个集合,分别为 1 ,2 ,3 .....n。有三种操件1 p q 合并元素p和q的集合2 p q 把p元素移到q集合中3 p 输出p元素集合的个数及全部元素的和。思路:并查集操作。1、3步比较容易实现,只要建立一个sum[],cnt[],记录每个结点相应值,和并时把值更新到根结点,输出时只要找到根结点输出其值即可。但2操作有点麻烦,并查集没有删除操作。原先以原创 2014-02-27 15:54:12 · 988 阅读 · 0 评论 -
并查集扩展应用(好)uva12232
题意:有两种操作,一个是I p q v告诉你 x[p]^x[q]=v,一个是查询k个数的异或和,问是否出现矛盾以及能否确定答案很经典的并查集问题首先我们可以虚拟一个根节点x[n]=0,这样所有的I p v都可以转换成 x[p]^x[n]=0.另w[a]=x[a]^x[f[a]]即本身和父节点的异或值, 那么如何合并呢?记fp=f[p],fq=f[q],x[p]^x[q]=v,另f[fp]=原创 2014-02-26 21:47:57 · 619 阅读 · 0 评论