https://pintia.cn/problem-sets/994805342720868352/problems/994805345078067200
就是建树,然后遍历。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N],n;
unordered_map<int,int>mp,l,r;
int build(int l1,int r1,int l2,int r2)
{int root=a[l1];int k=mp[root];if(k>l2) l[root]=build(l1+1,l1+k-l2,l2,k-1);if(k<r2) r[root]=build(l1+k-l2+1,r1,k+1,r2);return root;
}
vector<int>ans;
void dfs(int u)
{if(l[u]) dfs(l[u]);if(r[u]) dfs(r[u]);ans.push_back(u);
}
int main(void)
{cin>>n;for(int i=1;i<=n;i++) cin>>a[i];for(int i=1;i<=n;i++) cin>>b[i],mp[b[i]]=i;build(1,n,1,n);dfs(a[1]);cout<<ans[0];return 0;
}

1138 Postorder Traversal (25 分)【难度: 一般 / 知识点: 建树】相关推荐

  1. PAT甲级1138 Postorder Traversal:[C++题解]前序遍历和中序遍历建树

    文章目录 题目分析 题目链接 题目分析 做过前面几道题,发现这道题就是一道模板题,递归建树即可. 还是使用笔者熟悉的hash表来找根,进行优化. 请移步至笔者的另一篇文章:PAT甲级1020 Tree ...

  2. 1066 Root of AVL Tree (25 分)【难 / 知识点: 平衡树 未完成】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805404939173888 平衡树之前学过,不过有忘完了,有时间补吧

  3. C++学习之路 | PTA(甲级)—— 1043 Is It a Binary Search Tree (25分)(带注释)(精简)

    1043 Is It a Binary Search Tree (25分) A Binary Search Tree (BST) is recursively defined as a binary ...

  4. 1086 Tree Traversals Again (25分)

    1 题目 1086 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-r ...

  5. PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642 题目描述: A Binary Search Tr ...

  6. LeetCode 145. Binary Tree Postorder Traversal

    原题链接在这里:https://leetcode.com/problems/binary-tree-postorder-traversal/ 题目: Given a binary tree, retu ...

  7. LeetCode 889. Construct Binary Tree from Preorder and Postorder Traversal

    原题链接在这里:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/ 题 ...

  8. 【PAT乙】1080 MOOC期终成绩 (25分)

    problem 1080 MOOC期终成绩 (25分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想要获得一张合格 ...

  9. tree traversal (树的遍历) - postorder traversal (后序遍历)

    tree traversal (树的遍历) - postorder traversal (后序遍历) 1. tree traversal - 树的遍历 二叉树的遍历 (traversing binar ...

最新文章

  1. 布局类型java_java – 我们可以为所有屏幕大小制作一种布局类型
  2. 【会议邀请】第5届语言与智能高峰论坛将于本周五在线召开
  3. 计算机组装高考真题,年计算机组装与维修高考题.pdf
  4. Intel和AMD的最新视频编码/解码基准测试
  5. 一个div压在另一个div上面_【CSS小分享】用CSS画一个新拟态风格键盘
  6. python自定义修饰器_Python概述
  7. 面试精讲之面试考点及大厂真题 - 分布式专栏 03 阿里华为资深HR面试套路全揭晓
  8. Python之数据分析(figure图形对象、Numpy连线特殊点、图像多元布局)
  9. 最新福昕高级阅读编辑器
  10. Android UI开发第四十篇——ScrollTricks介绍
  11. 大司、小司、外包公司
  12. Unity3D 实现阴阳师 画符
  13. 程序员鄙视链, 所有工程师都鄙视php工程师, 为什么
  14. 360安全浏览器总是锁屏解锁后自启动打开网页,烦~
  15. 2020年创业风口:社交电商
  16. ES的创建索引和文档操作
  17. Windows 下无痛安装 TensorFlow (GPU版)
  18. wps插入visio流程图
  19. 怎么注册b5服务器,CSGO-B5开放注册
  20. 广告买量支付方式 cpa cpc cps cpt

热门文章

  1. Keras: 多输入及混合数据输入的神经网络模型
  2. 蓝桥杯_算法训练_ALGO12_摆动序列
  3. MongoDB数据库--扩展Base64,算法
  4. java.nio.file.NoSuchFileException
  5. Select 多个表并且相关联转置
  6. 为什么创业者专注做一个产品最好?
  7. Inside ASP.NET 2.0 – Controls Model(转载)
  8. windo.open 全攻略
  9. CMM (培训计划-Training Program)
  10. stm32f103插拔pc端的串口引起的问题及解决办法