hihoCoder week10 后序遍历
题目链接 https://hihocoder.com/contest/hiho10/problem/1
给出先序 中序 求 后序
#include <bits/stdc++.h>
using namespace std; const int N = ; char a[N], b[N]; void divide(int sa,int ea,int sb,int eb)
{
if(sa > ea || sb > eb)
return ;
int tmp = -;
for(int i=sb; i<=eb; i++)
if(a[sa] == b[i]) {
tmp = i;
break;
}
int la = tmp - sb;
// 递归左子树
divide(sa+, sa+la, sb, tmp-);
// 递归右子树
divide(sa+la+, ea, tmp+, eb);
cout << a[sa];
} int main()
{
freopen("in.txt", "r", stdin);
scanf("%s %s", a, b);
int len = strlen(a);
divide(, len-, , len-);
return ;
}
hihoCoder week10 后序遍历的更多相关文章
- hihocoder 1049 后序遍历
#1049 : 后序遍历 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在参与过了美食节之后,小Hi和小Ho在别的地方又玩耍了一阵子,在这个过程中,小Ho得到了一个非常 ...
- hihoCoder 1049 后序遍历 最详细的解题报告
题目来源:后序遍历 解题思路:开始时我只知道先通过先序.中序求出二叉树,然后再后序遍历二叉树,这当然也是一种解题思路,但是会做一些无用功,比如:计算二叉树.其实,可以直接通过先序序列和中序序列直接求出 ...
- hihocoder 1049 后序遍历树
#include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #inc ...
- 【hihoCoder】1049.后序遍历
问题:http://hihocoder.com/problemset/problem/1049?sid=767510 已知一棵二叉树的前序遍历及中序遍历结果,求后序遍历结果 思路: 前序:根-左子树- ...
- 【HIHOCODER 1049】 后序遍历
描述 在参与过了美食节之后,小Hi和小Ho在别的地方又玩耍了一阵子,在这个过程中,小Ho得到了一个非常有意思的玩具--一棵由小球和木棍连接起来的二叉树! 小Ho对这棵二叉树爱不释手,于是给它的每一个节 ...
- HihoCoder第十周:后序遍历
也就在大二学数据结构的时候知道了树的前序遍历.后序遍历.中序遍历.之后就忘了,在之后就是大四研究生老师考我,我当时还不知道,真够丢人的.自此之后,知道了如何通过其中两个得到第三个,但是也没有编程实现过 ...
- [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...
- 剑指Offer面试题:22.二叉搜索树的后序遍历序列
一.题目:二叉搜索树的后序遍历序列 题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则返回true,否则返回false.假设输入的数组的任意两个数字都互不相同. 例如在下面 ...
随机推荐
- Python二分法查找
1.1二分前提是有序,,否则不可以2分,2分查找的时间复杂度是O(log n):排序后二分查找到适当的位置插入数值 lst = [37,99,73,48,47,40,40,25,99,51] def ...
- 139. Word Break(动态规划)
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...
- Discuz-阅读权限
设置用户浏览帖子或附件的权限级别,范围 0-255,0 为禁止用户浏览任何帖子或附件. 当用户的阅读权限小于帖子或附件的阅读权限许可(默认时为 1)时, 用户将不能阅读该帖子或下载该附件
- How to compute f1 score for each epoch in Keras
https://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2 https:// ...
- Sql日期时间格式转换[zhuan]
sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...
- 在lua中从一个字符串中移除空间源码
/* trim.c - based on http://lua-users.org/lists/lua-l/2009-12/msg00951.html from Sean Conner */ #inc ...
- 【Hadoop学习之十二】MapReduce案例分析四-TF-IDF
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 概念TF-IDF(term fre ...
- Gamma函数深入理解
Gamma函数 当n为正整数时,n的阶乘定义如下:n! = n * (n - 1) * (n - 2) * … * 2 * 1. 当n不是整数时,n!为多少?我们先给出答案. 容易证明,Γ(x + 1 ...
- Linux基础命令---文本格式转换fmt
fmt 将指定文件的内容,按照指定的格式重新排版,结果送到标准输出. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 ...
- TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow
TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow 只需在cmd中输入pip ...