HDU 1710 二叉树的遍历 Binary Tree Traversals
Binary Tree Traversals
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4330 Accepted Submission(s): 1970
In a preorder traversal of the vertices of T, we visit the root r followed by visiting the vertices of T1 in preorder, then the vertices of T2 in preorder.
In an inorder traversal of the vertices of T, we visit the vertices of T1 in inorder, then the root r, followed by the vertices of T2 in inorder.
In a postorder traversal of the vertices of T, we visit the vertices of T1 in postorder, then the vertices of T2 in postorder and finally we visit r.
Now you are given the preorder sequence and inorder sequence of a certain binary tree. Try to find out its postorder sequence.
1 2 4 7 3 5 8 9 6
4 7 2 1 8 5 9 3 6
#include<stdio.h>
#include<string.h>
int str1[],str2[],str3[];
int sum;
int getlen(int root,int str2[]){
int cnt=;
int i=;
while(){
if(str2[i]==root)
return cnt;
i++;
cnt++; }
}
void change(int m,int str1[],int str2[]){
if(m==)
return ;
int len=getlen(str1[],str2);
change(len,str1+,str2);
change(m--len,str1++len,str2+len+);
str3[++sum]=str1[];
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
sum=-;
memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
memset(str3,,sizeof(str3));
for(int i=;i<n;i++)
scanf("%d",&str1[i]);
for(int i=;i<n;i++)
scanf("%d",&str2[i]);
change(n,str1,str2);
for(int i=;i<n;i++)
printf("%d%c",str3[i],i==n-?'\n':' ');
}
return ;
}
HDU 1710 二叉树的遍历 Binary Tree Traversals的更多相关文章
- [Leetcode 144]二叉树前序遍历Binary Tree Preorder Traversal
[题目] Given a binary tree, return the preordertraversal of its nodes' values. Example: Input: [1,null ...
- hdu 1710 二叉树的遍历
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1710 大意:给出一个二叉树的前序和中序,求其后序遍历 ps:1.在写链表时,需要写明typedef str ...
- 二叉树垂直遍历 · Binary Tree Vertical Order Traversal
[抄题]: 给定二叉树,返回其节点值的垂直遍历顺序. (即逐列从上到下).如果两个节点在同一行和同一列中,则顺序应 从左到右. 给定一个二叉树 {3,9,20,#,#,15,7} 3 /\ / \ 9 ...
- HDU 1710 Binary Tree Traversals (二叉树遍历)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 1710 Binary Tree Traversals 前序遍历和中序推后序
题链;http://acm.hdu.edu.cn/showproblem.php?pid=1710 Binary Tree Traversals Time Limit: 1000/1000 MS (J ...
- hdu1710(Binary Tree Traversals)(二叉树遍历)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 1710 Binary Tree Traversals(树的建立,前序中序后序)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 1701 (Binary Tree Traversals)(二叉树前序中序推后序)
Binary Tree Traversals T ...
- HDU 1710 二叉树遍历,输入前、中序求后序
1.HDU 1710 Binary Tree Traversals 2.链接:http://acm.hust.edu.cn/vjudge/problem/33792 3.总结:记录下根结点,再拆分 ...
随机推荐
- 21.C#序列过虑、排序、let子句和连接(十一章11.3-11.5)
哈哈,隔了一个星期,再怎么样都要发一篇,要多看书啊,书不能停~~~ 使用where子句进行过虑 where子句的语法格式如下:where 过虑表达式 例子:新建一个珠宝类,如下: class Jewe ...
- Bootstrap3.0学习第二十五轮(JavaScript插件——折叠)
详情请查看http://aehyok.com/Blog/Detail/31.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 第三十五课:Ajax详解
一个完整的Ajax请求: var xhr = new (self.XMLHttpRequest || ActiveXObject)("Microsoft.XMLHTTP"); ...
- 第三章:Javascript类型、值和变量。
计算机程序的运行需要对值(value)比如数字3.14或者文本"hello world"进行操作,在编程语言中,能够表示并操作的值的类型叫做数据类型(type),编程语言最基本的特 ...
- RESTful WebService入门(转)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://lavasoft.blog.51cto.com/62575/229206 REST ...
- php_curl模拟登录有验证码实例
<?php/** * @author 追逐__something * @version $id */define('SCRIPT_ROOT',dirname(__FILE__).'/');$ac ...
- poj3580 伸展树(区间翻转 区间搬移 删除结点 加入结点 成段更新)
好题.我做了很久,学了大牛们的区间搬移.主要的代码都有注释. #include<cstdio> #include<cstring> #include<iostream&g ...
- linux更改文件所有者命令chown命令的使用困惑
[berry@berry:practice] ls -lrt total -rwxrwxrwx berry berry Dec : f1.txt -rwxrwxrwx berry berry Dec ...
- BZOJ3720 Gty的妹子树
Description 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕…… Gty神(xian)犇(chong)从来不缺妹子…… 他来到了一棵妹子树下,发现每 ...
- mint锁屏设置
心血来潮,给笔记本装了linux,版本是当下最火的mint.唔,使用体验不错-下面记录的是修改mint锁屏相关设置的修改方式. In Linux Mint 13, the screen lock fe ...