![](https://img-blog.csdnimg.cn/20190918140012416.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
树和二叉树
树
柏油
不负冬日春晓 不负青春韶华
展开
-
hihoCoder 1049 : 后序遍历 (二叉树遍历)
#1049 : 后序遍历 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在参与过了美食节之后,小Hi和小Ho在别的地方又玩耍了一阵子,在这个过程中,小Ho得到了一个非常有意思的玩具——一棵由小球和木棍连接起来的二叉树! 小Ho对这棵二叉树爱不释手,于是给它的每一个节点都标记了一个标号——一个属于A..Z的大写字母,并且原创 2017-05-11 11:44:31 · 350 阅读 · 0 评论 -
HDU Binary Tree Traversals(二叉树重建+dfs)
二叉树重建+DFS :中序遍历和先序遍历(或后序遍历)可以重建二叉树 ,和UVA 536一样的题 #include const int maxn=1000+10; int pre_order[maxn],in_order[maxn]; int lch[maxn],rch[maxn]; int flag; //标识符号,用于输出格式的判断 int build_tree(int L1,in原创 2017-02-11 21:03:05 · 259 阅读 · 0 评论 -
UVA 536 Tree Recovery 二叉树重建(重建二叉树+DFS)
本题起初采用的是二叉树重建+dfs完成,然后看见网上不用建树也可以完成,也尝试了这种方法 通过中序排列和先序排列(或后序排列)可以重建二叉树,AC代码如下: 二叉树重建+DFS: #include #include using namespace std; const int maxn=26+2; char pre_order[maxn],in_order[maxn]; //先序、中序 i原创 2017-02-11 20:19:53 · 313 阅读 · 0 评论 -
hihoCoder #1014 : Trie树
#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程的学习道路上一同前进。 这一天,他们遇到了一本词典,于是小Hi就向小Ho提出了那个经典的问题:“小Ho,你能不能对于每一个我给出的字符串,都在这个原创 2017-05-02 19:52:13 · 217 阅读 · 0 评论 -
S-Trees UVA712(二叉树)
题目读了半天,差点被吓住!题目本身很简单,就是一颗满二叉树,向左(2*temp),向右(2*temp+1),最后减去(1 #include #include using namespace std; const int maxn=1<<8; const int maxn2=10000; char X[8][2]; char Term[maxn]; char Common[maxn2]; int原创 2017-01-24 22:39:42 · 514 阅读 · 0 评论 -
HDU 3791 二叉搜索树 (基础题)
#include #include using namespace std; const int maxn=1024; int tree1[maxn],tree2[maxn]; void insert(char s,int *tree){ int t=1; while(tree[t]!=-1){ if(s else if(s>tree[t])t=2*t+1; } tree[t原创 2017-02-11 22:11:17 · 300 阅读 · 0 评论 -
Quadtrees UVA 297 四分树
// 2 1 // 3 4 对于四分树来说,给出了它的先序序列就可以确定整棵树了,因为对任意一个节点不是叶子就是父节点,对于一个父节点一定有四个子节点(就和完全二叉树一样,通过先序就可以确定整棵树了)。 题目大意是:整块的黑色区域的像素是1024,因为有些部分白色,所以通过四等分直到整个小区域都是黑色为止,最小可以分为(32*32=1024)个,每个小区域表示1像素。所以程序中通过递原创 2017-01-11 20:01:59 · 349 阅读 · 0 评论 -
The Falling Leaves 下落的树叶 UVA 699(二叉树)
#include#includeusing namespace std;const int maxn=10000;int sum[maxn];void buildtree(int t){ int temp;cin>>temp; if(temp==-1)return ; sum[t]+=temp; buildtree(t-1);buildtree(t+1);}bool int原创 2017-01-09 15:42:33 · 335 阅读 · 0 评论 -
Not so Mobile 天平 UVA839
#includeusing namespace std;//通过引用返回左右重物之和bool solve(int& W){ int Wl,Dl,Wr,Dr; cin>>Wl>>Dl>>Wr>>Dr; bool b1=true,b2=true; if(!Wl)b1=solve(Wl); if(!Wr)b2=solve(Wr); W=Wl+Wr; return原创 2017-01-09 10:23:57 · 214 阅读 · 0 评论 -
Dropping Balls 小球下落 UVA 679
解题思路:本题数据比较大,所以不采取数组储存;题目中的小球个数 I 如果为奇数时,它往左边走的小球个数是(I+1)/2个;偶数是往右边 I/2个。 #includeint main(){ int T; while(scanf("%d",&T)==1 && T!=-1){ while(T--){ int D,I; scanf("%d%d",&D,&I);原创 2017-01-07 23:51:51 · 274 阅读 · 0 评论