题目大意:2567是给出一棵树,让你求出它的Prufer序列.2568时给出一个Prufer序列,求出这个树. 思路:首先要知道Prufer序列.对于随意一个无根树,每次去掉一个编号最小的叶子节点,并保存这个节点所连接的节点所得到的序列就是这棵树的Prufer序列. 这个序列有十分优雅的性质.它能与无根树一一相应.因此.两个标号一样的无根树得到的Prufer序列也一定是一样的. 此外,设一个节点的度数是d[i],那么他会在Prufer序列中出现d[i] - 1次. 2567:记录每个节点的度.依…
Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2350   Accepted: 906 Description A tree (i.e. a connected graph without cycles) with vertices numbered by the integers 1, 2, ..., n is given. The "Prufer" code of such a…
Tree Recovery POJ - 2255 根据树的前序遍历和中序遍历还原后序遍历. (偷懒用了stl的find) #include<iostream> #include<string> using namespace std; string s1,s2; int len; void work(int l1,int r1,int l2,int r2) { if(l1==r1) { cout<<s1[l1]; return; } if(l1>r1) retur…
二叉树 在计算机科学中,二叉树是每个结点最多有两个子树的有序树.通常子树的根被称作“左子树”(left subtree)和“右子树”(right subtree).二叉树常被用作二叉查找树和二叉堆或是二叉排序树.二叉树的每个结点至多只有二棵子树(不存在出度大于2的结点),二叉树的子树有左右之分,次序不能颠倒.二叉树的第i层至多有2的 i -1次方个结点:深度为k的二叉树至多有2^(k) -1个结点:对任何一棵二叉树T,如果其终端结点数(即叶子结点数)为,出度为2的结点数为,则=+ 1. 基本形态…
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree. You may assume each number in the sequence is unique. Follow up: Could you do it using only constant space complexity? 这道题让给了我们一个一维数组,让我们…
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf…
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree. You may assume each number in the sequence is unique. Consider the following binary search tree: 5 / \ 2 6 / \ 1 3 Example 1: Input: [5,2…
[leetcode]1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree 链接 leetcode 描述   Given two binary trees original and cloned and given a reference to a node target in the original tree.   The cloned tree is a copy of the original tr…
题意:在树中,每次删去节点值最小的叶子结点. 每删去一个点,就给出与这相连的点的值,直到最后只剩下一个根结点,给这N-1个数,重新建立这个树. 思路: 给出的节点号按次序存入到数组a中,将未给出的数存入到rest数组中去,并从小到大排序. 每次取一个给出的节点,那么我们需要求出与该点相连的被删去的点v. 而点v必定为 “不会在之后的数据中出现的值(即之后删除的叶子节点中再也没有与之相连的,即改点为叶子节点)” 和 “当前rest数组中最小的值”  中的最小值. 那么只要预处理一下,对于给出的节点…
题目链接: http://poj.org/problem? id=1780 Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2037   Accepted: 751 Description KEY Inc., the leading company in security hardware, has developed a new kind of safe. To unlock it, you don't nee…