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.总结:记录下根结点,再拆分 ...
随机推荐
- asp.net网站安全常见问题与防范
1:SQL 注入 2:XSS 3:CSRF 4:文件上传 1:SQL 注入 引起原因: 其实现在很多网站中都存在这种问题.就是程序中直接进行SQL语句拼接.可能有些读者不太明白. 下面通过一个登录时对 ...
- 解决HTML5布局,兼容IE问题
当我们使用h5的新标签,header,footer,aside,section,article...时,会遇到低版本IE不兼容问题,如下图: 解决方案:引入如下JS代码,即可 (这里我就直接放源码了, ...
- [转载]NSString中判断中文,英文,数字
曾有需求做个用户名中非法字符的判断,要求是只能输入中英文和数字,其他字符一律非法,故写了下边一个程序mark一下吧~~ NSString *testString = @"春1mianBU觉晓 ...
- 【C#】依赖于SharpZipLib的Zip压缩工具类
上班第二天下班,课外作业,实现一个ZIP压缩的工具类.本来想用Package,但是写完了才发现不能解压其他工具压缩的zip包,比较麻烦,因此本工具类依赖了第三方的库(SharpZipLib vers ...
- eclipse快捷键的使用及概述
<eclipse快捷键的使用及概述> <Eclipse概述> Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服 ...
- iOS开发小技巧--设置cell左右有空隙,设置分割线的新思路,重写setFrame:让别人在外界无法修改控件的大小
如图:需要自定义cell
- hdu3535 混合背包
分三种情况. 至少取一种 那可以直接取 或者从上一种情况来取.dp[i][k]=max(dp[i][k],dp[i-1][k-a[j].c]+a[j].v,dp[i][k-a[j].c]+a[j].v ...
- BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)
今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...
- 洛谷P2024 食物链
挺神奇 题目描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B 吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种 ...
- Spring3.2.2之后不赞成使用queryForInt
原来: public int getMatchCount(String username,String password){ String sql="select count(*) from ...